2016-10-11 84 views
0

我使用的是C#上的硒webdriver,我正在使用頁面對象模塊。現在我需要一個語法來明確地等待,因爲我已經擁有了webelement。顯式等待Selenium Webdriver用於手動元素

[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.driver, TimeSpan.FromSeconds(Time)); 
wait.Until(ExpectedConditions.ElementExists(by)); 

現在我需要使用該元素在手。

回答

4

您應該嘗試使用ExpectedConditions.ElementToBeClickable這將接受IWebElement以及輸入要等到元素是可見的,如下啓用: -

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

在預期條件下不接受ElementToBeClickable。它給出.........'OpenQA.Selenium.Support.UI.ExpectedConditions'不包含'ElementToBeClickable –

+0

的定義你可以看到這個鏈接的c#文檔,https://seleniumhq.github.io/ selenium/docs/api/dotnet/html/M_OpenQA_Selenium_Support_UI_ExpectedConditions_ElementToBeClickable_1.htm它由'ExpectedConditions'支持。我很奇怪你爲什麼會得到錯誤 –

+0

你使用什麼版本的硒? –

0

預期狀況的方法採取By當作它們的參數,你想使用ElementIsVisible,即下面應該工作:

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