Reputation: 963
I am new to this and I am trying to understand the usage of selenium and XPath
string exp = "//*[@id=\"g_1_bHwVovAN\"]/td[2]";
var dateTime = chromeDriver.FindElementsByXPath(exp);
With this code, I can only take 1 element. How can I change this "bHwVovAN" part, so I can reach the all that kinds of elements on the website.
string exp = "//*[@id=\"g_1_[^[0-9+]]\"]/td[2]";
var dateTime = chromeDriver.FindElementsByXPath(exp);
I tried to use regex, but It did not work. It did not recognize regex parts. Also, I looked at the other posts, and tried to use matches, and also did not work. How can I solve it?
If I did not write clear and correct way, I am also new to English. Sorry
Upvotes: 0
Views: 369
Reputation: 52665
There is a matches()
function in XPath 2.0
that would solve your issue, but selenium
doesn't support this XPath
version.
You can try below to match elements with id
attribute that starts with "g_1_"
:
string exp = "//*[starts-with(@id,\"g_1_\")]/td[2]";
Upvotes: 1