Tag Archives: selenium

How WebDriverWait works differently for WebElements defined by driver.findElement versus PageFactory initialization

When it comes to using WebDriverWait to wait for WebElement properties,like text or attributes, when sending WebElements as properties generated via PageFactory, that will work properly. However when using ‘driver.findElement()’ to identify the WebElements required as parameters in the WebDriverWaits, that will fail. Here is the reason why. Continue reading How WebDriverWait works differently for WebElements defined by driver.findElement versus PageFactory initialization

Use waits as assertions for your Selenium tests

Selenium tests tend to make a lot of use of assertions, to check that some actions have been performed on the front-end or that some WebElement properties are the expected ones. And by assertions, I mean, mostly: assertEquals or assertTrue, as these are the most commonly used ones.

Assertions fail too often due to the condition they are checking not being fulfilled by the time the assertion code executes. Had the assertion run a few seconds later, in many cases, it would have passed. It’s all about timing. In my previous posts I described some of the WebDriverWait based methods you can find in my ‘thewaiter’ library. In this post I want to highlight how you can use these methods to replace your assertions. Continue reading Use waits as assertions for your Selenium tests

thewaiter: wait for WebElement text. To equal, contain a String with variations.

Element text is something you will often check for when writing Selenium tests. Whether it equals a given String, or contains a given String. But you can extend your checks to whether: the element text equals/contains a String ignoring the case of the two, or whether the element text equals/contains a String ignoring any whitespace the two might contain. Continue reading thewaiter: wait for WebElement text. To equal, contain a String with variations.

thewaiter: wait for an element to be displayed with Selenium

A very hot topic when testing with Selenium is how to wait for a WebElement to be displayed. I wrote about this some while back, and that post is one of my most read on this blog. In this new post i will revisit the subject, by providing a new version of that method, using Java 8. It can be found in ‘thewaiter’ library in two variants: with a default timeout, and with a signature that allows a timeout parameter to be specified when calling it. Continue reading thewaiter: wait for an element to be displayed with Selenium

thewaiter: waiting for a URL in the browser to equal or contain a String, with Selenium

In some tests it is not enough to just wait for a page to fully load, but instead you need to make sure that the URL corresponding to that page is the expected one. Maybe you clicked on a button and need to make sure an expected page/URL opened, or maybe you are opening a page but a redirect changes the URL to something else than the initial page had. For such tests you can use the URL related wait methods from ‘thewaiter’ library, to wait until the URL is the correct one, before performing the rest of the test. Continue reading thewaiter: waiting for a URL in the browser to equal or contain a String, with Selenium

thewaiter: clicking on an element by using waits with Selenium

One of the most common ways of interacting with a page displayed in a browser, in Selenium tests, is clicking on a WebElement. But many times, due to the timing when the click happens, it will fail, since the WebElement that needs to be clicked is not yet available. This might be because some Javascript events have not finished enabling that WebElement, or other similar issues. Making clicks reliable can be done by using WebDriverWait, to wait until the click can actually happen.

Continue reading thewaiter: clicking on an element by using waits with Selenium

thewaiter: opening a page and waiting for it to load with Selenium

In this post i will discuss the methods you can find in thewaiter library, for waiting for a page to load completely. I will show the methods you can use from thewaiter that can help you with these waits, and some test examples for each, that you can also find in GitHub.   Continue reading thewaiter: opening a page and waiting for it to load with Selenium