Selenium WebDriver Click() fails with IE9

前端 未结 10 1863
礼貌的吻别
礼貌的吻别 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:53

    try this..
    WebElement hiddenWebElement =d.findElement(By.xpath(xpath));
    ((JavascriptExecutor)d).executeScript("arguments[0].click()",hiddenWebElement);

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

    May be you need to set Enable Native Events to "true" when you are running it on IE and if you want to run the same code in FF and Chrome,then you need to enable Native Events to "true" in those Browsers too.

    You can do that when you are setting the Browser on which you wish to run.

    0 讨论(0)
  • 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.

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

    Use FindElement(By.CSSSelector("'CSSPath'")); If you have any CSS applied to the button, its more consistent alternatively write other multiple statements to find the element with alternative means such as ID,tag or so with the WebDriverWait Method

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

    I see multiple solution here, but i thought I would share what worked for me in case anyone else out there needed a different approach. I had a similar problem, for me the solution was as simple as clicking using a different method

    For example

    btn.Sendkeys(Keys.Enter); 
    
    0 讨论(0)
  • 2021-02-15 18:09

    Try code -

    driver.FindElement(By.Id("btn")).sendkeys("\n");
    
    0 讨论(0)
提交回复
热议问题