问题
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