mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.18k stars 1.52k forks source link

Horizontal scroll bar intercepting element clicks #2013

Open titusfortner opened 2 years ago

titusfortner commented 2 years ago

I'm not sure if this started failing with FF 99 or 100. An element is supposed to be scrolled into view at the bottom of the page and clicked.

The problem is that if there is a horizontal scroll bar on the page, it needs to wait a second before it goes away. If the scroll bar covers the center of the element, there will be an Element Click Intercepted.

Not sure if it needs to click through the scroll bar, or automatically wait for the scroll bar to go away like the user would.

System

Testcase

HTML: https://github.com/SeleniumHQ/selenium/blob/trunk/common/src/web/scrolling_tests/page_with_double_overflow_auto.html

This fails:

    driver.findElement(By.id("btn")).click();

This passes:

    try {
      driver.findElement(By.id("btn")).click();
    } catch (Exception e) {
      Thread.sleep(1200);
      System.out.println("Excepted and Waited");
      driver.findElement(By.id("btn")).click();
    }

Stacktrace

Element <button id="btn" type="button"> is not clickable at point (42,203) because another element <div> obscures it
Build info: version: '4.1.4', revision: 'Unknown'
System info: host: 'SL-1495.lan', ip: '192.168.1.243', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '11.5', java.version: '11.0.12'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Command: [3da29b59-ab5b-4557-b3d5-abd2a165e6d2, clickElement {id=63e59f06-5b81-42ed-8aaf-68cd85af4b08}]
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 100.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:buildID: 20220428192727, moz:debuggerAddress: localhost:64391, moz:geckodriverVersion: 0.31.0, moz:headless: false, moz:processID: 55352, moz:profile: /var/folders/fx/nlx77ccs72g..., moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: MAC, platformName: MAC, platformVersion: 20.6.0, proxy: Proxy(), se:cdp: ws://localhost:64391/devtoo..., se:cdpVersion: 85.0, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Element: [[FirefoxDriver: firefox on MAC (3da29b59-ab5b-4557-b3d5-abd2a165e6d2)] -> id: btn]
Session ID: 3da29b59-ab5b-4557-b3d5-abd2a165e6d2
org.openqa.selenium.ElementClickInterceptedException: 
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
jsa34 commented 1 year ago

I have just encountered this issue, and trying to find a workaround, so can confirm it still appears to be present

whimboo commented 1 year ago

Sorry for the delay in response here. The initial HTML testcase actually works just fine for me locally on MacOS. Maybe there has something changed in the meantime? It would be good to know if the testcase is still valid for you @titusfortner. And if not what needs to be modified. Thanks.

jsa34 commented 1 year ago

I have resolved this with a workaround:

        // Disables scroll bar appearing:
        // causes issues with driver clicking this instead of the intended target
        firefoxOptions.addPreference("widget.gtk.alt-theme.scrollbar_active", false);
        firefoxOptions.addPreference("widget.gtk.overlay-scrollbars.enabled", false);
        firefoxOptions.addPreference("layout.css.scrollbar-gutter.enabled", false);
        firefoxOptions.addPreference("widget.windows.overlay-scrollbars.enabled", false);
jsa34 commented 1 year ago

I think the scroll bars behave differently depending on the OS, hence different preferences needed for Windows vs Linux (perhaps I have also just assumed this issue, just from description, is the same as the behaviour I was seeing - I didn't rerun the exact repro above, but I was using Linux env)

titusfortner commented 1 year ago

Well, the reproduction code I provided is not accurate, so there's that.

There were 5 tests failing for this issue in Java Selenium code: https://github.com/SeleniumHQ/selenium/blob/selenium-4.8.0/java/test/org/openqa/selenium/ClickScrollingTest.java#L119

It looks like 3 of them that were failing are now passing. These are 2 still failing that I've reproduced with Ruby here on public pages (MacOS, latest Selenium/FF/Geckodriver):

irb(main):019:0> driver.get 'https://www.selenium.dev/selenium/web/scrolling_tests/page_with_double_overflow_auto.html'
=> nil
irb(main):020:0> element = driver.find_element(id: 'link').click
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8: Element <a id="link" href="target_page.html"> is not clickable at point (39,820) because another element <html> obscures it (Selenium::WebDriver::Error::ElementClickInterceptedError)                                                                                                    

and

irb(main):028:0> driver.get 'https://www.selenium.dev/selenium/web/scroll3.html'
=> nil
irb(main):029:0> driver.find_element(id: 'button2').click
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8: Element <button id="button2"> is not clickable at point (94,817) because another element <html> obscures it (Selenium::WebDriver::Error::ElementClickInterceptedError)
whimboo commented 1 year ago

@titusfortner both cases work for me when I run on MacOS X. Do you have a more complete trace log for both? It's really strange that a html element obscures an element living within the page itself.

whimboo commented 1 year ago

Btw do you run those tests stand-alone or through the bazel test framework? If it's the latter which command would I have to execute? Maybe Selenium sets some preferences which might cause that failure?

whimboo commented 1 year ago

@titusfortner I would appreciate if you find the time to give me the details in how to run the related tests. Thanks.

titusfortner commented 1 year ago

Looks like I have 13 open tickets on here, probably worth seeing if I can still replicate things.

tksjh commented 1 year ago

this issue still occurs, reproduction in java:

public class Issue2013 {

    private static final int PAGE_WIDTH = 100;
    private static final int PAGE_HEIGHT = 30;

    private File htmlFile;

    private File getHtml() throws IOException {
        if (htmlFile == null) {
            StringBuilder builder = new StringBuilder();

            builder.append("<html>");
            builder.append("<body style=\"width: ").append(PAGE_WIDTH).append("em;\">");

            for (int i = 0; i < PAGE_HEIGHT; i++) {
                builder.append("<p>");
                for (int j = 0; j < PAGE_WIDTH; j++) {
                    builder.append("<a href=\"#").append(i).append("-").append(j).append("\">");
                    builder.append("X");
                    builder.append("</a> ");

                    if (i != 0 && i != PAGE_HEIGHT - 1) {
                        break;
                    }
                }
                builder.append("</p>");
            }

            builder.append("</body>");
            builder.append("</html>");

            htmlFile = Files.writeString(File.createTempFile("issue2013_", ".html").toPath(), builder.toString()).toFile();
        }

        return htmlFile;
    }

    private void test(FirefoxOptions firefoxOptions) throws IOException {
        FirefoxDriver firefoxDriver = new FirefoxDriver(firefoxOptions);

        try {
            firefoxDriver.manage().window().setSize(new Dimension(PAGE_WIDTH*5, PAGE_HEIGHT * 10));

            firefoxDriver.get(getHtml().getAbsolutePath());

            List<WebElement> links = firefoxDriver.findElements(By.tagName("a"));

            for (WebElement link : links) {
                link.click();
            }
        } finally {
            firefoxDriver.quit();
        }
    }

    /**
     * This is failing.
     */
    @Test
    public void testOverlayScrollbars() throws IOException {
        test(new FirefoxOptions());
    }

    /**
     * This is passing.
     */
    @Test
    public void testSolidScrollbars() throws IOException {
        FirefoxOptions firefoxOptions = new FirefoxOptions();

        firefoxOptions.addPreference("widget.gtk.overlay-scrollbars.enabled", false); // for linux platform
        firefoxOptions.addPreference("widget.windows.overlay-scrollbars.enabled", false); // for windows platform

        test(firefoxOptions);
    }
}
manikumarnune123 commented 11 months ago

I think issue depends on screen resolution where test is running.

whimboo commented 7 months ago

Looks like I have 13 open tickets on here, probably worth seeing if I can still replicate things.

@titusfortner did you had a chance to check? I'm still not able to reproduce the issue. Thanks.