Selenium Wait Confusion...

36 views
Skip to first unread message

mawa316

unread,
Apr 25, 2018, 2:18:28 PM4/25/18
to Selenium Users
Hi all,

I've always been a little confused about waits using Selenium and I'm hoping someone can shed some light on something.

What is the difference between the following two waits...

wait.Until(d => driver.FindElementByXPath("//div[contains(text(), 'Blah-Blah')]").Displayed);

wait
.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//div[contains(text(), 'Blah-Blah')]")));


I've found in some of my tests that when I have one in place and if fails, if I use the other method it works.

Any help in differentiating the two would be greatly appreciated!

Thanks!

Jonathan Herbaut

unread,
Apr 26, 2018, 4:27:47 AM4/26/18
to Selenium Users
I'm not sure about the answer but it seems like that with :
  • The first one : You expect that your element is always in your DOM but not visible
  • The second one : You expect that your element will be visible (but not necessary in your dom during the wait request)

The first one will send you a ElementNotFoundException when you ask for the Displayed attribute.

With the second one, you never make a direct search of your element, that's why the exception will not be fired and this solution is clearly better if this element must be seen before the wait timer.

Reply all
Reply to author
Forward
0 new messages