<a href="/MIS/PreLog/UserLogin.aspx" target="_blank">Login</a
我正在尝试为上面的登录链接编写xpath,但它无法正常工作。
driver.findElement( By.xpath("//a[contains(@href,'/MIS/PreLog/UserLogin.aspx') and @id='login']" ).click();
请给我解决方案..
答案 0 :(得分:0)
在你的xpath中,
driver.findElement( By.xpath("//a[contains(@href,'/MIS/PreLog/UserLogin.aspx') and @id='login']" ).click();
我没有看到任何@id
属性。
另外,为什么要特别选择xpath?您可以使用driver.findElement(By.LinkText("Login"))
编辑1:试试这个
driver.findElement( By.xpath("//*[contains(@href,'UserLogin') and text()='Login']" )).click();
答案 1 :(得分:0)
您的代码中的定位器可以修改并写如下,请检查这应该有效,
driver.findElement( By.xpath("//*[contains(@href,'UserLogin') and text()='Login']" )).click();