[英]Difficulty clicking an anchor tag using href as locator
How to locate identifiers in Selenium
for the following line of code? 如何在
Selenium
找到以下代码行的标识符?
<a href="loginPage" class="loginBtn" data-toggle="modal" data-target="rnr-loginPanel">Login</a>
I have tried: 我努力了:
driver.findElement(By.xpath("//a [contains ( @href = 'loginPage' )]")).click();
but it is not working for me. 但这对我不起作用。
There is a syntax problem with the contains keyword in your xpath. xpath中的contains关键字存在语法问题。 Following should work -
以下应该工作-
driver.findElement(By.xpath("//a[contains(@href,'loginPage')]")).click();
Also, a better and easier way would be 另外,更好更好的方法是
driver.findElement(By.className("loginBtn")).click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.