Reputation: 23
I've been trying to test a web application that generates html id's with a random value in the middle. For instance: attribute_new_12493044135_name The attribute defines the class of object that I want to find and the "name" is the unique part of this string. The problem is that I don't have Xpath 2.0 and thus can't use ends-with on the script. Can anyone help? I've tried to use Selenium Webdriver and IDE, and couldn't find an answer.
Upvotes: 1
Views: 1334
Reputation: 27
Also using a combination of css locators instead of the XPath will work:
[id*=attribute_new_][id*=_name]
OR:
[id^=attribute_new_][id$=_name]
Here's what the signs mean:
"^" - prefixes / starts with
"$" - suffixes / ends with
"*" - substrings / contains
Upvotes: 0
Reputation: 588
You are indeed correct you can not use the ends-with function if you do not have access to the Xpath 2.0 library. But you do have access to all the Xpath 1.0 functions. http://www.edankert.com/xpathfunctions.html
You have two functions you can use to xpath to your element.
contains(): //*[contains(@id, 'name')]
substring(): //*[substring(@id, string-length(@id)-3)="name"]
The 3 in string-length is the number of characters of your locator minus 1. ie 'name' has 4 characters so 4 - 1 = 3
Good Luck!
Upvotes: 3