Selenium Webdriver:元素不可见异常 [英] Selenium Webdriver: Element Not Visible Exception

查看:38
本文介绍了Selenium Webdriver:元素不可见异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在此网站

上单击简单登录按钮的代码

import java.util.concurrent.TimeUnit;导入 org.openqa.selenium.By;导入 org.openqa.selenium.WebDriver;导入 org.openqa.selenium.firefox.FirefoxDriver;公开课报告{公共静态无效主(字符串 [] args){WebDriver 驱动程序 = 新的 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 的原因

一个在

第二个(你需要的)在

因此将您的 xpath 更改为如下所示,它将解决您的问题:

By.xpath("//div[@class='page']//div[@id='_loginButton']")

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();

    }
}

I am getting following error:

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

解决方案

You have two buttons with given xpath on this page, first is not visible, thats why you are getting ElementNotVisibleException

One is under <div class="loginPopup">

Second (the one you need) is under <div class="page">

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆