Unified Functional Testing Practitioners Forum
Showing results for 
Search instead for 
Do you mean 

xpath for div and span doesn't work

Occasional Visitor

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.

 

 

1 REPLY
Highlighted
Valued Contributor

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