Re: xpath for div and span doesn't work (210 Views)
Reply
Occasional Visitor
oculuss
Posts: 2
Registered: ‎05-31-2013
Message 1 of 2 (241 Views)

xpath for div and span doesn't work

Go to google.com and add any object on the page to your local repository. Rename the browser object to "browser" and google's page to "Google".

 

Run the following code:

 

SystemUtil.CloseProcessByName("IExplore.exe")
systemutil.Run  "iexplore.exe", "http://google.com/"
Browser("Browser").Page("Google").Sync
Set objDesc = Description.Create
objDesc.Add "xpath", "//a"
Set links =  Browser("Browser").Page("Google").ChildObjects(objDesc)
msgbox links.count

 

I get 36 links total on the page, which is correct. Now change "//a" to "//span". This should now get you a count of all spans. Run the code again. I get 0, which is not correct. I double checked using a plugin called firepath for firebug in firefox that there are indeed spans on googles homepage (44 to be exact). So far, working types are:

 

table

a

 

Tags that don't work:

script

div

span

tbody

 

Anyone know what the deal is? I am using QTP 11 build 1018 with IE 9.

 

 

Valued Contributor
Anshoo_Arora
Posts: 82
Registered: ‎07-06-2011
Message 2 of 2 (210 Views)

Re: xpath for div and span doesn't work

Add the following line to your description and try again:

 

objDesc.Add "micclass", "WebElement"

 


--
Anshoo Arora
Relevant Codes
LinkedIn
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.