我在C#开始了一个Selenium项目.尝试等待页面完成加载,然后才进行下一步操作.
我的代码看起来像这样:
loginPage.GoToLoginPage();
loginPage.LoginAs(TestCase.Username, TestCase.Password);
loginPage.SelectRole(TestCase.Orgunit);
loginPage.AcceptRole();
Run Code Online (Sandbox Code Playgroud)
在loginPage.SelectRole(TestCase.Orgunit)中:
RoleHierachyLabel = CommonsBasePage.Driver.FindElement(By.XPath("//span[contains(text(), " + role + ")]"));
RoleHierachyLabel.Click();
RoleLoginButton.Click();
Run Code Online (Sandbox Code Playgroud)
我搜索元素RoleHierachyLabel.我一直在尝试使用多种方式等待页面加载或搜索元素属性允许一些超时:
1. _browserInstance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
你会如何解决这个障碍?
c# pageload ui-automation selenium-firefoxdriver selenium-webdriver