这是我的代码,用于单击一个简单的登录按钮Website
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 秒
您在此页面上有两个具有给定 xpath 的按钮,第一个按钮不可见,这就是您收到 ElementNotVisibleException 的原因
一颗在下<div class="loginPopup">
第二个(你需要的)在下面<div class="page">
因此,将您的 xpath 更改为如下所示,它将解决您的问题:
By.xpath("//div[@class='page']//div[@id='_loginButton']")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)