11

I am facing this problem on Firefox v.59, Selenium 3.11.0. I just click on an element, like this:

webDriver.findElement(By.id("row_0")).click();

and I get exception:

org.openqa.selenium.ElementNotInteractableException: Element <tr id="row_0" class="row_0 txtSearchColor1"> could not be scrolled into view

I already try with JavascriptExecutor like this:

js.executeScript("arguments[0].scrollIntoView(true);", webDriver.findElement(By.id("row_0")));
js.executeScript("arguments[0].click();", webDriver.findElement(By.id("row_0")));

but nothing works, it does nothing. This is element HTML:

<tr id="row_0" class="row_0 txtSearchColor1">
   <td></td>
   <td></td>
   <td></td>
</tr>

Note that, all the solutions work normally on Chrome (v65) and this element is visible. Does anyone have the same problem and a solution? Thanks

EDIT: HTML code of the elements: enter image description here

3
  • 1
    Does it work on Firefox<59? Mar 24, 2018 at 8:31
  • What happens when you do? "scrollIntoView(false);" Mar 26, 2018 at 20:35
  • @VishalAggarwal Hi, I already tried it js.executeScript("arguments[0].scrollIntoView(false);", element); , but it did nothing, it just bypassed the block, no exception. As you can see my discussion below, I tried with both whole row (throw exception) or one column (just bypassed), but nothing worked
    – Ragnarsson
    Mar 27, 2018 at 7:51

6 Answers 6

13

A workaround that works for me so far is that I use a 'fake' tr:

  • Find the tr I want to click
  • Find a td that belongs to that tr and click on it. it works

This bug is reported on Bugzilla and this workaround is recommended

2
  • 1
    I am quite new to this and facing same issue for almost all my cases. I am not sure exactly what is mean by 'tr' and 'td' in workaround mentioned. 1. Find the 'tr' I want to click 2. Find a 'td' that belongs to that 'tr' and click on it, it would works. Jan 30, 2020 at 3:30
  • @Ragnarsson Ashwini attempted to comment on here but did not have the reputation, so I converted their answer to a comment here.
    – corsiKa
    Feb 1, 2020 at 17:09
4

I faced the same issue when I upgraded to new Firefox version 63. I have used the Actions class to click an element. Give a try!

WebElement  element = WebDriver.findElement("locator");               
Actions act=new Actions(driver);
act.moveToElement(element).click().perform();
0

Wait for sometime before clicking.Give the page some time to load/scroll to the element.

1
  • I tried everything: Thread.sleep() or explicit and implicit Wait or waitForPageLoad() with "return document.readyState" or I debugged it, and let it wait until everything stable before I moved to next line to click, but I still get the same error on Firefox
    – Ragnarsson
    Mar 26, 2018 at 8:49
0

I also use a javascript to scroll an element into view, but I use the x and y positions, and I also wait for jquery to be active:

public static void scrollIntoView(WebElement ele) {
    ((JavascriptExecutor)driver).executeScript("window.scrollTo(" + ele.getLocation().x + "," + ele.getLocation().y + ")");
    waitForJQueryToBeActive();
}

public static void waitForJQueryToBeActive() {
    Boolean isJqueryUsed = (Boolean) ((JavascriptExecutor) driver)
            .executeScript("return (typeof(jQuery) != 'undefined')");
    if (isJqueryUsed) {
        while (true) {
            // JavaScript test to verify jQuery is active or not
            Boolean ajaxIsComplete = (Boolean) (((JavascriptExecutor) driver)
                    .executeScript("return jQuery.active == 0"));
            if (ajaxIsComplete)
                break;
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
        }
    }
}
7
  • Thanks for your answer. I tried it, but unfortunately, it doesn't work too, it passes these lines and does nothing, like all my solutions. Of course, it works for Chrome, only Firefox doesn't.
    – Ragnarsson
    Mar 26, 2018 at 15:10
  • Does it attempt to scroll, at least, or does it just immediately fail? Perhaps you could try scrolling to another element that's at or below the desired one, then attempt to access the one you want? Mar 26, 2018 at 15:19
  • 1
    It doesn't attempt to scroll, it just rans through the block. I also tried your suggestion to findElements which has this one in the group, and I tried to click on it, and I get exactly error like others, "Element could not be scrolled into view" :(
    – Ragnarsson
    Mar 26, 2018 at 15:40
  • Can you share in your original post at least a segment of the HTML. I wonder if there might be an invisible blocker element of some kind, or perhaps is the element in an iframe? Mar 26, 2018 at 15:44
  • I don't think it is in a iframe, just table inside table. I updated my post. I tried to click all the ids around it, but nothing works.
    – Ragnarsson
    Mar 26, 2018 at 15:57
0

I was getting the same issue but below JavascriptExecutor works for me on Firefox

Please find the below code driver.get("https://www.icicibank.com/"); System.out.println(driver.getWindowHandle()); driver.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS); Setwind=driver.getWindowHandles(); for (String hand : wind) { driver.switchTo().window(hand); System.out.println("Window "+hand); } JavascriptExecutor js = (JavascriptExecutor) driver; //js.executeScript("document.querySelector("button[id=yourButton]").click()"); WebElement element = driver.findElement(By.xpath("//div[@id='push-modal-content' and @class='active']/div[@id='push-modal-close' and contains(text(),'Later')]")); js.executeScript("arguments[0].scrollIntoView();",element); try { Thread.sleep(10000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } js.executeScript("arguments[0].click();",element);

0

I had the same problem. Where I was unable to select a dropdown value with selectByValue, selectByIndex and selectByVisible text. I tried actions class and scrollBy using Javascript executor also. Nothing worked. After 1 day of trial and error, I came up with the below workaround,

public static void selectDropDownByVisibleText(WebElement element, String text){
        waitForPageLoad();
        String firstCharacterDropDownVal = ""+text.charAt(0);
        HashSet<String> uniqueDropDownVals = new HashSet<>();
        try {
            Select select = new Select(element);
            select.selectByVisibleText(text);
        }catch (ElementNotInteractableException e){
            Select select = new Select(element);
            //If dropdown is notInteractable then we are sending the first character of dropdown value
            //So each time the selected value in the dropdown will change. Once we reach our desiredDropdown value we exit
            while(!select.getFirstSelectedOption().getText().equalsIgnoreCase(text) &&
                    uniqueDropDownVals.add(select.getFirstSelectedOption().getText())) {
                element.sendKeys(firstCharacterDropDownVal);
            }
        }
        log.info("Selected dropdown by visible text "+text);
    }


public static void waitForPageLoad() {
        log.debug("Waiting for page to get loaded..");
        new WebDriverWait(Driver.getDriver(), Duration.ofSeconds(FIND_ELEMENT_WAIT_TIME)).
                ignoring(NoSuchElementException.class).ignoring(StaleElementReferenceException.class).
                until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
        log.debug("Page loaded successfully");
    }

I will explain the working. First it will try to select by visible text. If we get the exception it will enter inside the catch block. There we are sending the first character of the desired text on the dropdown webelement. So the dropdown element changes. Let's say the dropdown values are Apple,Aeroplane,Adam and I want to select Adam. First time I send 'A' on the webelement the dropdown changes to Apple. Then I add it to the HashSet and check whether the selected element is the desired element. if it matches then we break out of the while loop. If the same element is added twice, then the HashSet add method will return false. This will break us out of the while loop and keep us from entering into an infinite loop. So each time I enter 'A' the dropdown value changes to the next value that starts with 'A'. This is the approach. Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.