Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE Automation : getelementbyid returns .NULL.

Status
Not open for further replies.

newtofoxpro

Programmer
Sep 16, 2007
301
IN
loFrm = oIE.Document.getelementbyid('username')
WAIT WINDOW loFrm

Above code returns (Object)

loFrm = oIE.Document.getelementbyid('MobNo1')
WAIT WINDOW loFrm

returns .NULL.

In Internet Explorer I go VIEW (menu) & Source and it appear in NOTEPAD. I searched Id.
 
Case sensitivity?
And what is the html having the id MobNo1?

Bye, Olaf.
 
It is not fare to post 1000 lines of code here but it is part of code

<input name="MobNo1" type="text" maxlength="10" id="MobNo1" onfocus="if(this.value=='Mobile Number') this.value='';" onblur="if(this.value=='') this.value='Mobile Number';" style="padding: 4px 4px 3px 4px;" value="Mobile Number" />

 
Of course that is sufficent. Are you sure the DOM of the IE object is referring to the page you view the html source of?

eg check if [ id="MobNo1"] $ oIE.Document.innerhtml

Do you actually wait for the docuement complete or readystate = 4 before using getelementbyid? You might simply be doing this too early, when the document isn't loaded yet. Ajax/javascript creating page elements on body load might even take this one step further and you need to wayit for that to finish to get at the element.

Bye, Olaf.
 
Yes I am waiting for the document complete or readystate=4 I put this code

Do While oIE.busy Or oIE.ReadyState!=4
Enddo


Please give me some time for checking Document.innerhtml

Best Regards.
 
Thank you, I did not find the element which is on the web page. I tried to find as under

OutCode=oIE.Document.body.innerhtml
STRTOFILE(OutCode, "test.txt")

are you sure " oIE.Document.body.innerhtml " takes 100% code from web page ?
 
Well, I'm sure oIE.Document.body.innerhtml takes the html the oIE.Document has in it.

If you see something else via "view source", this may be because the oIE.Docuemnt has a frameset or a redirection. The browsers view source is the culprit, perhaps, it will show you the html of a frame, if the main page is a frameset.

So, how does the html you saved vis STRTOFILE look like? Is it a frameset perhaps, does it include javascript or a meta tag loding a .js file? OR a meta tag doing a redirect?

Bye, Olaf.
 
I found that the element which I am going to access it is in TAB. I want to try if there is frameset, so how to get element in frames ?

One more thing, I found

1) oIE.Document.body.innerhtml generated file has something " IFRAME " & src="instant.jsp"

2) view source generated file has nothing as above.
 
Well, then the file you're is not your initial query, but you need to query instant.jsp to get at the html form.

It doesn't matter where the tag is embedded, getelementbyid get's at the element no matter if it's a root or nested element.

What you see in view source is the html generated by instant.jsp. The oIE object just has the iframe loading that jsp and you don't automate the final fill html page, but just the frameset, just as I suspected already.

Instead of loading your initial URL, try to load the smae url but replace the last part with instant.jsp and see what the innerhtml of that will be.

Bye, Olaf.

 
Instead of loading your initial URL, try to load the smae url but replace the last part with instant.jsp and see what the innerhtml of that will be. "

Your trick works, but

oIE.document.getelementbyid("Mob_No_1").Value="trial"

foxpro does not create error on above line but web page does not implemented.
 
One more thing,

Your trick works to get html code from .JSP only. Because if I feed another element and .click() on submit it generates error.

So, I think I will have to try from main url.
 
while googling I found something like but unable to implement.

To retrieve any value from an HTML Form element on a jsp page you need to use the implicit HttpServletRequest object's getParameter(String s) method. The HttpServletRequest object is available to all jsp pages and is named request. The String argument of the method getParameter(String s) is the elements name whose value you want to retrieve.
 
The ServerRequest object exists ONLY on the server (hence its name). It is used in generating the HTML displayed in the browser.

The browser only knows about the generated HTML, not any of the code that executes inside the JSP on the server.

(JSP is the java equivalent of ASP in the Microsoft world.)
 
The browser only knows about the generated HTML, not any of the code that executes inside the JSP on the server.

that's why I am not getting element. Am I right ?
 
No, you're just seeing the iframe and the iframe loads another inside that page, what is retrieves is not the jsp it also is exectued at the server, but it's result is makeing up the iframe content. And if you initially and just load the iframe content and not the frameset, then you'll be able to see the same source code you now see via view source in the browser. The browser context menu is from the iframe content, the oIE.Document is the frameset instead.

Bye, Olaf.
 
Thank you Olaf, it sounds like hope is there... Please post how to use frameset instead of oIE.Document
 
I already said what to do, reread my posting from 8 Oct 11 10:18:

Instead of loading your initial URL, try to load the smae url but replace the last part with instant.jsp and see what the innerhtml of that will be.

Bye, Olaf.
 
Yes, I have tried as you advised. If I run web-page with only last part instant.jsp it works I can access element ( I can feed text from foxpro) but when I submit it generates error.

If I run web page with original URL submit works. There must be the way to access element from different page/frame.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top