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.
 
Here's what happens when browsing an iframe:

frameset.html said:
<html>
<body>
<iframe src="iframe.html">
</iframe>
</body>
</html>

iframe.html said:
<html>
<body>
<p id="content">this is the content</p>
</body>
</html>

Save those two codes into 1. frameset.html and 2. iframe.html and then load frameset.html in your browser. View sourcecode will show you the iframe.html, while automation of the browser will show you the frameset.html

An iframe is just like a browser in the browser. You won't get there via browser automation, unless you do as the browser does and load the inner page itself.

See?

Bye, Olaf.
 
Thank you Olaf, you have better explained. I tried and understood what exactly going on to me. Let me try again.
 
Olaf, Please help I can not do it independently...

What I tried...

I run web browser with main URL. which has iframe

myframe=oIE.document.getelementbyid("frame")
xx=myframe.contentWindow.document.body.innerHTML
STRTOFILE(x,"xx.txt")

this way I get code in instant.jsp

myframe.contentWindow.document.getelementbyid('MobNo1').Value('test')

OLE error code xxxx : Not implemented
 
Okey. then submit button on instant.jsp does not work. (Error on pages)
 
I think I got it:

Using my example thi get's the Frame:

Code:
oie = CreateObject("internetexplorer.application")
oie.Navigate2("file:///C:/my/frameset.html")
oFrame = oIE.document.getElementsByTagName("iframe")

Now to get the paragraph tag with ID "content" from within that frame:

oContent = oFrame.item(0).getElementByID("content")
? oContent.innerhtml

And I now see the essential difference of the different getElement-functions of javascript and the DOM: If it's one element by the name of the function (eg getElementByID, as an ID has to be unique), then the resulting object is the tag node itself.

The function getElementsByTagName() on the other side has the plural Elements in it, and generally returns a collection of tag nodes as items collection, therefor even if it's just one frame you need item(0), oFrame is not the frame itself, it is a tag node collection with only one item in it.

In one step you can make it:

Code:
? oIE.document.getElementsByTagName("iframe").item(0).contentWindow.document.getElementByID("content").innerHTML

But there is no way getting more direct to the paragraph with ID "content", you first need a grip on the inner document of the iFrame.

Your mention of "contentWindow" helped a lot.

So more general in a case you want to get at the document object of a frame you

Code:
oIE = createobject("internetexplorer.application")
oIE.navigate2("file:///C:/my/frameset.html")
Do While oIE.busy Or oIE.ReadyState!=4
   doevents
Enddo
oFrames = oIE.Document.getElementsByTagName("iFrame")
* looping all oFrames items in oFrames.item(n)
For Each oFrame in oFrames 
  ? oFrame.contentWindow.Document
  ? oFrame.contentWindow.Document.body.outerhtml
Endfor

And with oFrame.contentWindow.Document you can begin your real search for the element with ID "MobNo1". If you have more than one iFrame in the outer document you need to see which one contains the tag you're really after.

Bye, Olaf.
 
Olaf, The solution which I discussed with you, till today I could not implement to myapplication. Very crude but many times worked & many times not is under

I think I still stick with the subject that finding element on the web-page and feed programatically.

oIE = CREATEOBJECT([InternetExplorer.Application])
oIE.Navigate("oIE.Visible = .T.
sp=Createobject("Wscript.Shell")
sp.SendKeys(REPLICATE("{TAB}",5))
sp.SendKeys("{ENTER}")

This way I have to reach to the element by # of tabs, feed what I want and ENTER. This way failed to the website which updated on daily basis.

Do you know ? As <SendKeys> send keys from foxpro to web-page, the command which mouse click from foxpro to web-page.

Thank you
Best Regards.
 
I already gave you a way (my previous lengthy post) to get at the iFrame content/elements/tags programmatically. Before we discuss a further way to solve your problem, have you tried that?

Bye, Olaf.
 
Yes, but I still don't understand what you mean with "could not feed with element".

A little code of yours could help enlighten me how you used mine and what you do with the oFrame reference, that does not work for you.

Besides, in the end you'd be much better with using a dedicated product to send text messages instead of misusing some website offering free SMS service. In most cases you'd be limited to a certain amount of SMS per day anyway and automating this for your product, even just for yourself is quite useless.

Bye, Olaf.
 
This is true, there is limitation of # of smses & it may be misusing.

My plan : How to provide sms services to my users.

Option 1 : Via free website, I know there is limitation & not for commercial use. And one more thing is if sms receiver is registered to DO NOT DISTURB he may not receive sms. Yet, Option should be there

Option 2 : Via web but paid services like BULK SMS etc.,

Option 3 : Via Mobile/Cell... Mobile should connect via data-cable or Blue tooth ( Till today, I don't know how to send sms via CELL)

Apart from above, I have tried your code as well as mine.

myframe=oIE.document.getelementbyid("frame")
xx=myframe.contentWindow.document.body.innerHTML
STRTOFILE(xx,"xx.txt")

With this, if I view xx.txt I can found element ID, even I can tried to feed like
**********************************************************
oFrames=oIE.Document.getElementsByTagName("iFrame")
oFrames.Document.getelementbyid("MobNo1").Value="test"

retuns error Unknown name
**********************************************************
myframe=oIE.document.getelementbyid("frame")
myframe.contentWindow.document.getelementbyid('MobNo1').Value('test')

returns error Not Implemented.
**********************************************************
oFrames = oIE.Document.getElementsByTagName("iFrame")
oFrames.contentWindow.Document.getelementbyid('MobNo1').Value('test')

retuns error Unknown name

**********************************************************
oFrames = oIE.Document.getElementsByTagName("iFrame")
oFrames.Document.getelementbyid('MobNo1').Value('test')

retuns error Unknown name
 
You didn't used my code using "contentWindow". The one line code I gave you could be modified this way to your situation:

loMobNo = oIE.document.getElementsByTagName("iframe").item(0).contentWindow.document.getElementByID("MobNo1")

? loMobNo1.Value
loMobNo1.Value = "your value here"

Something like that.

Bye, Olaf.
 
Your code works. Credit goes to you.
Thank you.
Best Regards.


(Opportunity is like an ice; if you think more about it....It melts)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top