2013-10-24 9 views
6

は、だから私はこの素晴らしい機能を使用して開始しました:SeleniumのC#ポートでWebDriverWaitのFindsByアノテーションを使用する方法はありますか?

[FindsBy(How = How.CssSelector, Using = "div.location:nth-child(1) > div:nth-child(3)")] 
public IWebElement FirstLocationTile { get; set; } 

しかし、問題は、私のWebDriverWaitコードで動作するようには思えないということです!

私のFirstLocationTileを再利用できない具体的な例です。それは持っていることを主張する:

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(BaseTest.defaultSeleniumWait)); 
wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("div.location:nth-child(1) > div:nth-child(3)"))); 

アイデア?

+0

私はC#を使用しませんが、ExpectedConditionsの多くが 'WebElement'ではなくByだけを受け入れることを知っています。しかし、Javaでは、要素が表示されるまで待つ(存在しない、可視にする)ことは、WebElementでできることです。 –

+0

FindsByはすべてのWeb要素でエラーが発生するように試みました。 FindElement(By.Id/Xpath work。[JavaのPageFactoryの例](http://startingwithseleniumwebdriver.blogspot.com.au/2015/02/wait-in-page-factory.html)。PageFactoryのinit要素はどこにありますか?どのような種類の[待機](http://automationtricks.blogspot.com.au/2015/02/what-is-implicit-home.php)は、 explicit-fluent-wait.html)? – lloyd

答えて

0

ExpectedConditionsを使用する場合、ExpectedConditionsはロケータのみを引数として受け入れるため、ロケータで識別することができます。

ただし、ExpectedConditionsはwait.until()で使用できる唯一の引数ではありません。代わりにラムダ式で要素を使用することができます。

^これはC#、Python、およびその他の言語に当てはまります。

An example lambda expression use can be found in the C# documentation、および例は、あなたが達成しようとしているものについては、以下である:

wait.Until(FirstLocationTile => FirstLocationTile.Displayed && FirstLocationTile.Enabled); 

要素in the C# documentationにはVisibleプロパティが存在しないので、私は、一例として表示され、有効に使用します。

関連する問題