Selenium, wait for element, page object model, c # bindings

How can we wait for the IWebElement to be (re) attached to the DOM? My scenario looks like I pick one value from dropdown1 and after the bind data binding happens in dropdown2. So when my test goes how to select "foo" from Dd1 then select "bar" from Dd2 -> i get an exception, there is a race condition as Dd2 has not been mapped yet. Now I know that we have a WebDriverWait class and we could use the Until smth method like this:

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
wait.Until(By.Id("foo"));

      

But I really wouldn't want to cast the locator string ("foo") to my test logic as it seems to beat the point of using the page object models. When using the page object model, I already have an instance of IWebElement

[FindsBy(How = How.Id, Using = "ctl00_MainContentPlaceHolder_actionButtonBarControl_btnSave")]
    public IWebElement BtnSave { get; set; }

      

So, do you know any ways to implicitly wait until the IWebElement is ready to communicate?

+3


source to share


3 answers


Hi, I know him a little later, but I had the same problem and got around it by doing the following (using your code):

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
wait.Until(By.Id(_pageModel.BtnSave.GetAttribute("id"));

      



Then it just returns the value of the ID attribute and stops you from polluting your test code by looking for elements. Hope it helps.

+3


source


If you don't want to use locator values

, then you can use for Implicit Wait instead of using Explicit Wait. An implicit wait also causes the instance driver

to wait for a specified period of time.

Actual difference to Explicit Wait is that it will tell Web driver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available.The default setting is 0.

Code:



  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

      

One thing to keep in mind is that once the implicit wait is set, it will remain for the lifetime of the WebDriver object instance.

For more information use this link http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html#implicitlyWait(long,java.util.concurrent.TimeUnit )

+1


source


What we do is pass in the original text of the selector, for example in seleniumRC css=a, xpath=b

.

We then have a method findElement

that will parse the query, get the matching one, By

and search for the item.

0


source







All Articles