I know that WebDriver can locate links through their text, using find_element_by_link_text or find_element_by_partial_link_text.
Is it possible to locate any element (such as li, div, span, ...) by text?
|
|
|
Yes. WebDriver supports using an XPath to locate an element by the text it contains. For example, the following XPath locates any div containing the string "Hello Justin":
|
|||||||||||||
|
|
As User246 mentioned, the xpath support depends on the browser. I have found a few problems with using XPath cross-browser. My solution for this problem was to find elements by tag name first, then iterate through the list of elements matching the tag and look for the attributes that I want to match on as well. |
|||
|
|