这是我单击此 网站 上的简单登录按钮的代码
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Reports {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("https://platform.drawbrid.ge");
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='_loginButton']")).click();
}
}
我收到以下错误:
线程“main”中的异常 org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与命令交互持续时间或超时:2.05 秒
原文由 Nik_stack 发布,翻译遵循 CC BY-SA 4.0 许可协议
您在此页面上有两个具有给定 xpath 的按钮,第一个是不可见的,这就是您获得 ElementNotVisibleException 的原因
一个在
<div class="loginPopup">
第二个(你需要的那个)在
<div class="page">
所以改变你的 xpath 看起来像这样,它会解决你的问题: