Selenium Webdriver:元素不可见的异常 [英] Selenium Webdriver: Element Not Visible Exception
问题描述
以下是我在网站上点击简单登录按钮的代码
Here is my code to click a simple login button on this 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:元素当前不可见,因此可能无法与$ b $进行交互b命令持续时间或超时:2.05秒
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with Command duration or timeout: 2.05 seconds
推荐答案
你有两个给定xpath的按钮页面,第一个是不可见的,这就是为什么你得到ElementNotVisibleException
You have two buttons with given xpath on this page, first is not visible, thats why you are getting ElementNotVisibleException
一个在< div class =loginPopup>
第二个(你需要的那个)在< div class =page>
Second (the one you need) is under <div class="page">
所以改变你的xpath看起来像这样,它会解决你的问题:
So change your xpath to look like this, and it will fix your problem:
By.xpath("//div[@class='page']//div[@id='_loginButton']")
这篇关于Selenium Webdriver:元素不可见的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!