WebDriverException Element is not clickable in Selenium [duplicate]

谁都会走 提交于 2019-12-24 17:19:59

问题


Here is the error message:

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)

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

回答1:


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)')

or you can also do same using Actions class.

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

Possible duplicate of Debugging "Element is not clickable at point" error



来源:https://stackoverflow.com/questions/52811266/webdriverexception-element-is-not-clickable-in-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!