WebDriverException元素在Selenium中不可单击 [英] WebDriverException Element is not clickable in Selenium

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

问题描述

这是错误消息:

org.openqa.selenium.WebDriverException: unknown error: Element <div class="col-md-2 col-sm-2 hidden-xs days" id="lblday3">...</div> is not clickable at point (799, 308). Other element would receive the click: <div class="modal-body text-center">...</div>
  (Session info: chrome=69.0.3497.100)

大家好,以上异常是在我的项目的ThankYou页面中引发的.我已经尝试更改等待时间,但是它也不起作用.下面是我使用的方法.

Hi everyone, the above exception was thrown in my ThankYou page in my project. I've tried to change the wait time but it also doesn't work. Below is the method I used.

public void Clickthankyou() throws InterruptedException
    {
        if(driver.findElement(By.xpath("//*[@id='id_appoint']/h2")).isDisplayed())
        {

        WebDriverWait wait = new WebDriverWait(driver, 6);  
        WebElement elem =wait.until(ExpectedConditions.elementToBeClickable(Dateselect));

        if(elem.isDisplayed())
        {
            elem.click();
        }

        Thread.sleep(2000);

        driver.findElement(Clickbook).click();
        }
        else
        {
            driver.navigate().back();
        }

推荐答案

此异常的基本原因是由于用户看到的浏览器窗口的ViewPort. 您需要滚动到特定元素,然后单击它.
关键是元素不可见,因此不适合单击. 好的,请使用此代码使用JavascriptExecutor进行修复,

The basic reason of this exception is due to ViewPort of Browser window which is seen by the user. You need to scroll to specific element then click on it.
Key thing is element is not visible so not eligible for clicking. ok use this code for do the fix using JavascriptExecutor ,

JavascriptExecutor js = (JavascriptExecutor) driver; 
js.executeAsyncScript('arguments[0].scrollIntoView(true)', driver.findElement(By.xpath("//*[@id='id_appoint']/h2")))
js.executeAsyncScript('window.scrollBy(0,-150)')

,或者您也可以使用Actions类执行相同的操作.

or you can also do same using Actions class.

new Actions(driver).moveToElement(driver.findElement(By.xpath("//*[@id='id_appoint']/h2"))).click().perform();

>调试元素不可点击"的可能重复项;错误

这篇关于WebDriverException元素在Selenium中不可单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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