Is there a way to use FindsBy annotation for WebDriverWait in a Selenium C # port?

So, I started using this wonderful function:

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

But the problem is that it does not work in my WebDriverWait code!

A concrete example where I cannot reuse my FirstLocationTile. He insists on having By .:

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

Any ideas?

+6
source share
1 answer

If you use ExpectedConditions, you can only identify with a locator, since ExpectedConditions only accepts a locator as an argument.

However, ExpectedConditions is not the only argument you can use in wait.until (). Instead, you can use your element in a lambda expression.

^ This is true for C #, Python, and other languages.

An example of using the lambda expression can be found in the C # documentation , and an example below for what you are trying to achieve:

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

I used Displayed and Enabled as an example since there is no Visible property for the document.

0
source

Source: https://habr.com/ru/post/956679/


All Articles