What will you learn in this course?

Are you struggling with working with HTML using Selenium WebDriver? Do you know how to easily identify and manipulate an element using Selenium WebDriver? How about performing a drag n’ drop on an element? If not, then these are just a few of the questions that will be answered in this course.

This course is a complete guide on working with web elements in Selenium WebDriver! Once you are finished with this course, you will know how to work with any web elements, anytime, on any web application.

In this course from Ultimate QA, you will learn:

– Basics of HTML

– All the different locator strategies for Selenium WebDriver

– How to identify web elements using Selenium WebDriver

– Master XPath

– Navigation with Selenium WebDriver

– Web element manipulation

– Web element interrogation

– Mouse and keyboard actions with Selenium WebDriver

– Performing actions such as drag n’ drop, drawing, hovering

– Implicit and Explicit waits

– How to properly handle element identification so that your tests are not flaky

– Expected Conditions in Selenium WebDriver

Take This Entire Course for Free

What will you learn in this lecture?

In this video, we will go through the explaining the solution to the quiz of the page objects in test automation course.

Selenium Tutorial – Page Objects in Test Automation Explaining the solution to the quiz

I hope that you spend some time trying that exercise and I hope that you’ve succeeded. If not it’s OK. It was really tough. I actually spent about 30 minutes trying to figure out how to automate the situation. And it’s because there are many variables on this page that make it extremely tough. For example when you first load the page you can’t just directly identify the toggle and try and open it by its locator because it’s not visible. And so you won’t be able to click on it. So that’s not going to work.

And what you’re going to get is element not clickable exception and that’s some other element is going to receive your click. So in that case what you need to do is to place focus on the actual element so that it’s visible now is going to be available for you to click on. There are several methods to do this utilizing any NY driver. I’m going to show you one but if you attempt to do that the method was going to happen it will definitely pull the element into focus is going to pull that element into focus and the page will look something like this. Yes. The element is in focus but it’s behind this Hetter up here. So again if you attempt to click on this you’re going to get another error telling you that this Hetter up here is going to receive the click because that toggle button is not visible. So what are you going to do. It’s really hard. What I decided to do was rather than placing focus on the element on the toggle I placed focus on this carousel of Polsce a ball of the toggle.

So now when I place focus on it the page is going to come to about this point.

And my toggle is clearly visible in the center of my screen and the ready to accept my clicks. That’s what I did. Let me show you the code. So here I road test five and as standard. I created another complicated page went to the complicated page and asserted that the complicated page opened successfully and nothing new here. What’s new here is I created a method called Open toggle and my open toggle is going to do all of those actions that I mentioned. I’m going to utilize the actions class to move to the element that I called the Post’s slider that pole slider that’s the element right above the toggle which I identified in this manner.

Now once we move to the element using the actions class then my toggle is open for clicking. So I just use the object repository in the toggle element which I identified in this manner and I clicked on it and that was fantastic. After clicking on it I wrote an assertion stating that the complicated page that the toggle is open and that is true. So to check that the toggle is open. I had to use a selenium web driver weight class which has an explicit weight instead of an implicit weight. I didn’t want to use an implicit weight because if you noticed here the toggle opens a little bit slow and an implicit wait has a time out of zero seconds. So if for whatever reason the toggle does not open fast enough your implicit wait also known as find element’s method is going to fail. So rather what you have to do is use an explicit weight.

I use an explicit weight and set a timeout of five seconds. I rafted in a try catch block and I’m checking to see if the elements I’m waiting until the expected conditions. That element is visible and the element that’s visible is my toggle inner text locator.

Let me go to the definition and my toggle text locator is of type by and I located it using XPath and making sure that it has text called Inside the toggle. So we wait until this element is visible if the element is not visible what’s going to happen is selenium is going to throw a web drive or timeout exception which we’re going to catch and return false to our method. If the element is visible however no exception is going to be thrown. And we’re going to return a true therefore giving us a fantastic test. Now that I’ve explained to you what I’ve done. Let me just run this test so that you can actually see it working.

Pin It on Pinterest

Share This