Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getElementByid("myObhectId") return null???
#1
Solved: 10 Years, 9 Months, 1 Week ago
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
Reply
#2
Solved: 10 Years, 9 Months, 1 Week ago
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
Reply
#3
Solved: 10 Years, 9 Months, 1 Week ago
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
Reply
#4
Solved: 10 Years, 9 Months, 1 Week ago
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Function return value is not passed during the 3rd iteration premanand1979 0 2,058 10-16-2014, 09:40 PM
Last Post: premanand1979
  how to remove null values in array venkatesh9032 0 2,771 02-19-2014, 06:51 PM
Last Post: venkatesh9032
  GetRoProperties("enabled") returns null? RandomGrin 3 7,030 02-28-2013, 11:27 PM
Last Post: RandomGrin
  Null value of the object swapna_gupta08 4 11,591 02-21-2012, 11:00 AM
Last Post: inborntester
  QTP Test results will return exit codes asrivastava 13 16,278 07-08-2011, 12:57 PM
Last Post: rajpes

Forum Jump:


Users browsing this thread: 1 Guest(s)