org.openqa.selenium.ElementNotInteractableException: Element could not be scrolled into view when trying to click a button

前端 未结 3 1057
离开以前
离开以前 2020-11-28 16:55

I\'m working with gecko driver selenium java with FF 60.0. Previously my code was working properly, but all of sudden, now every time I run it, it gives me an error as

相关标签:
3条回答
  • 2020-11-28 17:15

    Try to use javascriptexecutor as shown sample code below,

    JavascriptExecutor je = (JavascriptExecutor) driver;
    je.executeScript("arguments[0].scrollIntoView(true);",driver.findElement(By.xpath("//a[@href='/admin/worker-summary']")));
    
    0 讨论(0)
  • 2020-11-28 17:21

    This error message...

    Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <a class="bg-inverse text-white dropdown-item" href="/admin/worker-summary"> could not be scrolled into view
    

    ...implies that the GeckoDriver / FirefoxDriver was unable to interact with the desired element.

    Solution

    Once you locate the element btnWorkerSummary moving ahead as you are invoking click() instead of ExpectedConditions as visibilityOf you need to use elementToBeClickable() as follows:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@href='/admin/worker-summary']"))).click();
    

    However, another issue is the incompatibility between the version of the binaries you are using as follows:

    • Your Selenium Client version is 3.12.0.
    • Your JDK version is 1.8.0_51 which is ancient.

    Solution

    • Upgrade JDK to recent levels JDK 8u201.
    • Execute your @Test.
    0 讨论(0)
  • 2020-11-28 17:24

    You can simply try following js to scroll the page.Enter Pixel asper your requirement to scroll page. Here I use 3000 Px to scroll page to mid

       JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("window.scrollBy(0,3000)");

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