Skip to content

Click not triggering all events #403

Description

@skyhirider

Got another issue for you, test case in hand :)

When clicking via Selenium + Htmlunit only the click javascript event triggers, but doing the same in Firefox triggers mouse up, down and click.

The test case I tried:

class HtmlUnitClickTest {

    private WebDriver ffDriver;
    private WebDriver huDriver;
    private final static String buttonPage = "<button id=\"testButton\">Click me</button>\n" +
            "<div id=\"logArea\"></div>\n" +
            "<script>\n" +
            "    const button = document.getElementById('testButton');\n" +
            "    const div = document.getElementById('logArea');\n" +
            "\n" +
            "    button.addEventListener('mousedown', e => {\n" +
            "        console.log('up');\n" +
            "        div.innerHTML += \"up \";\n" +
            "    });\n" +
            "    button.addEventListener('mouseup', e => {\n" +
            "        console.log('down');\n" +
            "        div.innerHTML += \"down \";\n" +
            "    });\n" +
            "    button.addEventListener('click', e => {\n" +
            "        console.log('click');\n" +
            "        div.innerHTML += \"click \";\n" +
            "    });\n" +
            "\n" +
            "\n" +
            "</script>";


    @BeforeEach
    void initDrivers() {
        System.setProperty("webdriver.gecko.driver", "c:\\path\\geckodriver.exe");
        FirefoxOptions options = new FirefoxOptions();
        options.setLogLevel(FirefoxDriverLogLevel.FATAL);
        ffDriver = new FirefoxDriver(options);
        huDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX, true) {
            @Override
            protected WebClient modifyWebClient(WebClient client) {
                final WebClient webClient = super.modifyWebClient(client);
                WebClientOptions options = webClient.getOptions();
                options.setCssEnabled(true);
                options.setThrowExceptionOnScriptError(false);
                webClient.setJavaScriptErrorListener(new SilentJavaScriptErrorListener());

                return webClient;
            }
        };
    }

    @AfterEach
    void closeDrivers(){
        ffDriver.close();
        huDriver.close();
    }

    @Test
    void givenFFandHtmlUnit_whenClicking_registerThreeEvents() {
        Assertions.assertEquals(testClicks(ffDriver), testClicks(huDriver));
    }

    private String testClicks(WebDriver driver) {
        driver.get("data:text/html;charset=utf-8," + buttonPage);
        driver.findElement(By.id("testButton")).click();
        return driver.findElement(By.id("logArea")).getText();
    }

}

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions