Webdriver How to wait until the element is clickable in webdriver C#

前端 未结 4 1919
一整个雨季
一整个雨季 2020-11-29 08:56

There is a block Ui which covers all the elements for a few seconds after the Element have been generated in the browser because of this i facing a problem ,Since element ha

4条回答
  •  情歌与酒
    2020-11-29 09:00

    On our slower test runner computers it seemed the input element would be findable first, but still not clickable by the time that the script tried to send keys or a click to the input control. Waiting for "ElementToBeClickable" helped. Faster, more powerful test runner systems did not have this problem nearly as much.

    Here is code with a bit of context that seems to have improved things on my C# based Selenium tests. Also using SpecFlow and xUnit. We are using IE11 and IEDriverServer.exe.

    As of May 2019, the NuGet package containing this is DotNetSeleniumExtras.WaitHelpers.

    The key line is this one:

    wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By...

    Do this for the first input field on a new page, using a selector that points to the first input field you want to interact with. (By.XPath("")

    [Given(@"I have selected the link to the OrgPlus application")]
    public void GivenIHaveSelectedTheLinkToTheOrgPlusApplication()
    {
        _driver.Navigate().GoToUrl("http://orgplus.myorg.org/ope?footer");
    }
    
    [Given(@"I have selected the link to the OrgPlus Directory lookup")]
    public void GivenIHaveSelectedTheLinkToTheOrgPlusDirectoryLookup()
    {
        var wait = new WebDriverWait(_driver, new TimeSpan(0, 0, 30));
        var element = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//*[@id=\"lnkDir\"]")));
        IWebElement btnSearch = _driver.FindElement(By.XPath("//*[@id=\"lnkDir\"]"));
        btnSearch.SendKeys(Keys.Enter);
    }
    

提交回复
热议问题