Make Selenium Easy

Do You Know That Class ExpectedConditions is Not To Just Use With WebDriverWait?

If I ask you to verify if title of a web page is as expected or not in Selenium WebDriver – Java then probably you will use below lines of code:-

Or if I ask you to verify if any web element is present or not then probably you will write below lines of codes:-

Or if I ask you to check if an alert is present then accept it then probably you will write below lines of code :-

But do you know we have ready made methods available to check assertions quickly? Yes those are defined in ExpectedConditions class. This class contains Canned ExpectedCondions which are generally useful within webdriver tests. They have not mentioned anywhere that you can use it with explicit wait i.e. WebDriverWait and FluentWait.

Let’s rewrite above lines of code using methods of ExpectedConditions class.

To verify title

To verify if a web element is present

To verify if an alert is present and then accept it

To verify if a text box is present and type in to it

To switch to a frame if it is available

To switch to an iframe and click on an element

Complete Code :-

For negative cases, you can easily handle using try catch.

You can download/clone above sample project from here.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

Find all Selenium related post here, all API manual and automation related posts here and find frequently asked Java Programs here.

Many other topics you can navigate through menu.

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

Do You Know That Class ExpectedConditions is Not To Just Use With WebDriverWait?

by Amod Mahajan time to read: 2 min
0
%d bloggers like this: