How to get webDriver to wait for page to load (C# Selenium project)

后端 未结 7 1288
北荒
北荒 2020-12-04 22:57

I\'ve started a Selenium project in C#. Trying to wait for page to finish loading up and only afterwards proceed to next action.

My code looks like this:

<         


        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 23:29

    I usually use an explicit wait for this, and wait until an elements is visible, then proceed to the next action. This should look like this:

    WebDriverWait waitForElement = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
    waitForElement.Until(ExpectedConditions.ElementIsVisible(By.Id("yourIDHere")));
    

    More on Explicit waits here: Explicit waits Selenium C# and here WebDriver Explicit waits

提交回复
热议问题