我已经阅读了 xpath 教程并检查了许多其他帖子,因此我不确定我错过了什么。我只是想通过 xpath 找到以下元素:
<input class="t-TextBox" type="email" test-id="test-username"/>
我尝试了很多东西,例如:
element = findElement(By.xpath("//[@test-id='test-username']"));
错误是
Expression is not a legal expression
.我在 MacBook 上使用 Firefox
任何建议将不胜感激。
最佳答案
element = findElement(By.xpath("//*[@test-id='test-username']");
element = findElement(By.xpath("//input[@test-id='test-username']");
(*) - 任何标记名
关于xpath - Selenium WebDriver findElement(By.xpath()) 对我不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16952514/