Micro Focus QTP (UFT) Forums
getElementByid("myObhectId") return null??? - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: getElementByid("myObhectId") return null??? (/Thread-getElementByid-myObhectId-return-null)



getElementByid("myObhectId") return null??? - qtptester - 01-30-2013

Hello
I tried to look for the answer to my question before open a new topic but i did not founded it
i try to get and object of type webbutton from my application :

Code:
set input=Browser("title:=.*").page("title:=.*").Object.getElementByid("myObhectId")
then i clcik on it :

input.click

i have problems when the object is not present in the page
how can i test if getElementByid("myObhectId") returns an objecT?
i tried with following methos
isnull(input)
isobject(input)
but thet seem not work

thank in advance for your help
Dave


RE: getElementByid("myObhectId") return null??? - ravi.gajul - 01-31-2013

It means it is not returning any object. Please make sure that you are giving the right html id for the button you are trying to retrieve.
Example: on gmail login page the following msgbox displays true
When it doesn't find an element with specified id, qtp throws 'object required' error
Code:
set oBtn=Browser("name:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").object.getElementById("signIn")
If  isobject(oBtn) Then
    oBtn.Click
End If



RE: getElementByid("myObhectId") return null??? - qtptester - 01-31-2013

Thank you for your answer Ravi
but probably i did not explain fully the problem :

myObhectId is not an object that i have in myobject repository
now i want check if getElementById("myObhectId") returns me an object present in the page.

wrote my function as you did

Code:
set input=Browser("title:=.*").page("title:=.*").Object.getElementByid("myObjectId")

If  isobject(input) Then
    input.Click
End If


if i set an object id of an webutton present in my page it works correctly
but i need to check if getElementByid returns me no objects :

now if i write a wrong object id it still tries to do input.click
i don t know why isobject is not working how it was expected
but probably i don t know how getElementByid works

thank you


RE: getElementByid("myObhectId") return null??? - ravi.gajul - 02-01-2013

Hi,
It looks like it is returning an object for a wrong id .Probably there is another object with the wrong id you gave. Technically, when you try to retrieve an element by passing an invalid id, it throws.."object required error" as I have mentioned in the previous post.
Consider the same example I gave, but pass "sign1" as id you will see the error message in first step itself..the second line of code is not reached yet. If you don't see the error message, you either disabled the error prompt by using "On error resume next" statement somewhere in your code or in the settings "file->Setting->run ->When error occurs during run session(this is a drop down..chosen to proceed with next step)
Code:
set oBtn=Browser("name:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").object.getElementById("signIn1")
If  isobject(oBtn) Then
    oBtn.Click
End If