blueprintmrk / selenium-vba

Automatically exported from code.google.com/p/selenium-vba
0 stars 0 forks source link

find a text in a page and return its location #111

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hello , 

I am currently using the following function to look for a link in a page:
driver.findElementByLinkText(cell.Text)
Is it possible to look for a text in a page and then return its xpath , or id 
or name or class name ... and work with it afterwards
Thanks for your help

Original issue reported on code.google.com by alam...@gmail.com on 29 Oct 2014 at 4:57

GoogleCodeExporter commented 9 years ago
> Is it possible to look for a text in a page
Sure you can use an XPath or a Css expression:
Set elts = driver.findElementsByXPath("//*[contains(text(), 'your text')]")
Set elts = driver.findElementsByCssSelector("*:contains('your text')")

> return its xpath
No there is no command to get it, but you could execute some Javascript to 
compute it with the executeScript  command.

> or id or name or class name
The getAttribute command will get you an attribute:
Debug.Print driver.findElementById("your id").getAttribute("id")
Debug.Print driver.findElementById("your id").getAttribute("class")

Original comment by florentbr on 30 Oct 2014 at 12:20