Selenium - Element is not clickable at point

后端 未结 7 1296
无人共我
无人共我 2020-12-30 06:30

I am using selenium for test script. I am getting following error and this error randomly occur. When I run 10 times, I get this about twice. So it\'s not really reproducibl

相关标签:
7条回答
  • 2020-12-30 06:38

    I have solved by catching the exception and managing it like this:

            WebDriver driver = new ChromeDriver();
            WebElement element = driver.findElement(By.id("ID"));
            boolean clicked = false;
            do{
                try {
                    element.click();
                } catch (WebDriverException e) {
                    continue;
                } finally {
                    clicked = true;
                }
            } while (!clicked);
    
    0 讨论(0)
  • 2020-12-30 06:49

    There are a number of steps you can do in order to improve the stability while clicking on different UI elements:

    • Explicitly wait for it's presence in the DOM
    • Scroll into the element view
    • Check if clickable

    Does it helped the stability?

    WebDriverWait wait = new WebDriverWait(driver, 3)
    JavascriptExecutor js = ((JavascriptExecutor) driver)
    
    //presence in DOM
    wait.until(ExpectedConditions.presenceOfElement(By.id("ID")));
    
    //scrolling
    WebElement element = driver.findElement(By.id("ID")));  
    js.executeScript("arguments[0].scrollIntoView(true);", element);
    
    //clickable
    wait.until(ExpectedConditions.elementToBeClickable(By.id("ID")));
    

    Further, if you will decide to override the default Actions interface with more customized one, you can use two type of clicks (for example): click() which will have all those stability steps and fastClick() which will be the default clicking without any varification.

    0 讨论(0)
  • 2020-12-30 06:51

    click parent element of the element which you want to click. this can be workaround solution only.

    0 讨论(0)
  • 2020-12-30 06:55

    for best solution , use java script to focus element Using ----> JavascriptExecutor jsnew=(JavascriptExecutor) driver; WebElement element=driver.findElement(By.xpath("")); jsnew.executeScript("arguments[0].scrollIntoView({block:\"center\"});", element);

    In place of xpath you can use id , css selector : This scrollIntoView will bring the this specific element in middle of page , themn driver wil be able to hit element.

    if it is normal button or link , use jsnew.executeScript("arguments[0].click();",element);

    This is consistent solution for click.

    0 讨论(0)
  • 2020-12-30 06:57

    I was also facing same problem with Chrome. I have solved that putting one line of code before clicking on the element:

    scrollToViewElement(driver,xpath);
    
    0 讨论(0)
  • 2020-12-30 06:59

    I got the same issue due to one of spinner was hiding the element.

    I gave xpath and it resolved the issue. Other people suggested to 1. scroll 2. sleep also worked for them.

    0 讨论(0)
提交回复
热议问题