Selenium WebDriver Click() fails with IE9

前端 未结 10 1896
礼貌的吻别
礼貌的吻别 2021-02-15 17:13

(I\'ve looked at many other similar posts on SO and have unfortunately not been able to solve this problem, so here goes...)

I\'m using Selenium WebDriver (C# implementa

相关标签:
10条回答
  • 2021-02-15 18:10

    The following worked for me:

    @FindBy(id = "submit_action")
    WebElement submitButton_;
    ...
    public void clickSubmit() {
    
        if (driver_ instanceof InternetExplorerDriver) {
            ((JavascriptExecutor) driver_).executeScript("arguments[0].fireEvent('onclick');", submitButton_);
        }
        else {
            submitButton_.click();
        }
    }
    

    As fireEvent is only supported by IE hence the alternative.

    0 讨论(0)
  • 2021-02-15 18:10

    One more possible workaround can be like repeating clicking like:

    Btn.click();
    Btn.click();
    

    Because 1st click just set focus and 2nd one performs the real click. It worked for me.

    0 讨论(0)
  • 2021-02-15 18:17

    Is your site publicly available for test? Is your IE zoom level at 100%? It is a requirement for native click events to work from the documentation here

    The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.

    If this doesn't work then it seems a bug in webdriver. You should open an issue here.

    Having said this, you could probably go the Java script route in the meanwhile as a temporary solution. Something like,

    driver.navigate().to("javascript:document.getElementById('yoursubmitbutton').click()");
    
    0 讨论(0)
  • 2021-02-15 18:17

    It looks like it may be a problem with where the mouse click occurs. I tried using the Actions mechanism in Selenium to force a mouse-click with a bit of an offset. It successfully click the element:

    new Actions(GuiOps.driver).MoveToElement(e).MoveByOffset(5,5).ClickAndHold().Release().Perform();
    
    0 讨论(0)
提交回复
热议问题