显式等待Selenium Webdriver手中的元素

我在C#上使用selenium webdriver,我正在使用页面对象模块。 现在我需要在显式等待中使用语法,因为我已经掌握了webelement。

[FindsBy(How = How.Id, Using = "Passwd")] public IWebElement Password {get;set;} [FindsBy(How = How.Id, Using = "signIn")] public IWebElement Signin { get; set; } 

我需要等到找到Element Password。

在使用这个模块之前我使用的是:

 WebDriverWait wait = new WebDriverWait(driver.driver, TimeSpan.FromSeconds(Time)); wait.Until(ExpectedConditions.ElementExists(by)); 

现在我需要手中使用Element。

您应该尝试使用ExpectedConditions.ElementToBeClickable接受IWebElement和输入,并等待元素可见并启用如下: –

 WebDriverWait wait = new WebDriverWait(driver.driver, TimeSpan.FromSeconds(Time)); wait.Until(ExpectedConditions.ElementToBeClickable(Password)); 

请检查这是否有帮助

 WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until(driver => Password.Displayed); 

添加显式等待并等待Password.Displayed为true:

 [FindsBy(How = How.Id, Using = "Passwd")] public IWebElement Password {get;set;} [FindsBy(How = How.Id, Using = "signIn")] public IWebElement Signin { get; set; } WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until(Password.Displayed); 

完全披露,我在这里找到答案: https : //groups.google.com/forum/#!topic /webdriver / xdFsocNMSNc

预期的条件方法采用By作为他们的参数,并且您想要使用ElementIsVisible ,即下面应该工作:

 WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until(ExpectedConditions.ElementIsVisible(By.Id("Passwd")));