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

xpath for div and span doesn't work

Go to 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.Run  "iexplore.exe", ""
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:





Tags that don't work:






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



Valued Contributor
Posts: 82
Registered: ‎07-06-2011
Message 2 of 2 (264 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
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.