I've been through the xpath tutorials and checked many other posts, hence I'm not sure what I'm missing. I'm simply trying to find the following element by xpath:
<input class="t-TextBox" type="email" test-id="test-username"/>
I've tried many things, such as:
element = findElement(By.xpath("//[@test-id='test-username']"));
The error is Expression is not a legal expression
.
I'm using Firefox on MacBook
Any suggestion would be greatly appreciated.
Correct
Xpath
syntax is like:So you should write something like this:
You should add the tag name in the xpath, like:
(*) - any tagname
You can use contains too:
your syntax is completely wrong....you need to give findelement to the driver
i.e your code will be :
// your xpath is:
"//[@test-id='test-username']"
i suggest try this :
"//*[@test-id='test-username']"
You missed the closing parenthesis at the end: