Selenium WebDriver Click() fails with IE9

前端 未结 10 1865
礼貌的吻别
礼貌的吻别 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 17:58

    I had this problem. I can't remember the post where I found the resolution but I found that the following worked for me:

    On a button:

      var navButton = driver.FindElement(By.Id("NavButton"));
     ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].fireEvent('onclick');", navButton);
    

    Works every time.

    I was also having problems sending the click event to a table row. Sometimes the .Click() would actually send the event to the row above (we have a horribly complicated table structure which has a hidden radio button within it which is also not clickable with Selenium). The above hack wouldn't work with cells that were accessible through a FindElement.

    In the end the only thing that worked was to select the image within that row and send the click to that.

    var img = driver.FindElement(By.Id("fim{4C3DE9FA-45B0-40E0-BD95-9EE0374EA38A}"));
    ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].fireEvent('onclick');", img);
    

    Hope that helps.

提交回复
热议问题