Selenium WebDriver findElement(By.xpath()) not wor

2020-02-11 02:41发布

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.

8条回答
够拽才男人
2楼-- · 2020-02-11 03:20

You haven't specified what kind of html element you are trying to do an absolute xpath search on. In your case, it's the input element.

Try this:

element = findElement(By.xpath("//input[@class='t-TextBox' and @type='email' and @test-    
id='test-username']");
查看更多
狗以群分
3楼-- · 2020-02-11 03:26

Just need to add * at the beginning of xpath and closing bracket at last.

element = findElement(By.xpath("//*[@test-id='test-username']"));
查看更多
登录 后发表回答