我已經在C#中啓動了一個Selenium項目。試圖等待頁面完成加載,然後才能繼續下一個操作。如何讓webDriver等待頁面加載(C#Selenium項目)
我的代碼如下所示:
loginPage.GoToLoginPage();
loginPage.LoginAs(TestCase.Username, TestCase.Password);
loginPage.SelectRole(TestCase.Orgunit);
loginPage.AcceptRole();
內loginPage.SelectRole(TestCase.Orgunit):
RoleHierachyLabel = CommonsBasePage.Driver.FindElement(By.XPath("//span[contains(text(), " + role + ")]"));
RoleHierachyLabel.Click();
RoleLoginButton.Click();
我要尋找的元素RoleHierachyLabel。我一直在試圖用多種方式來等待頁面加載或搜索元素屬性,允許一些超時:
1. _browserInstance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
2. public static bool WaitUntilElementIsPresent(RemoteWebDriver driver, By by, int timeout = 5)
{
for (var i = 0; i < timeout; i++)
{
if (driver.ElementExists(by)) return true;
}
return false;
}
你會如何解決這個障礙?
優秀徹底的答案! 有沒有辦法等待彈出窗口加載? – Lars