Selenium 2.0b3 IE WebDriver, Click not firing

后端 未结 18 1963
我寻月下人不归
我寻月下人不归 2020-11-29 02:33

When using the IE driver with IE9, occasionally the Click method will only select a button, it wont do the action of the Click(). Note this only happens occasionally, so i d

18条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 03:07

    After a bit more searching i found two things that seem to have helped in repeatable tests:

    First i added an ImplicitlyWait of 5 seconds. Not sure if this is applied to all FindElement functions, but I have stopped getting most of the NoSuchElementException i was getting.

    OpenQA.Selenium.IE.InternetExplorerDriver driver = new OpenQA.Selenium.IE.InternetExplorerDriver();
    driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 0, 5, 0));
    //driver.Manage().Speed = Speed.Medium;
    

    Second i was having trouble with a Logout function and changed the code to:

    public LoginPageObject Logout() {
        Driver.FindElement(By.LinkText("Logout")).Click();
    
        OpenQA.Selenium.Support.UI.IWait wait = new OpenQA.Selenium.Support.UI.WebDriverWait(Driver, TimeSpan.FromSeconds(5));
        IWebElement element = wait.Until(driver => driver.FindElement(By.Name("username")));
    
        LoginPageObject lpage = new LoginPageObject(Driver);
        return lpage;
    }
    

    The explicit wait seems to handle what the ImplicitlyWait doesn't catch (i think because of redirects).

    http://code.google.com/p/selenium/source/browse/trunk/support/src/csharp/webdriver-support/UI/WebDriverWait.cs?r=10855

提交回复
热议问题