10 Selenium Issues You Should Know How to Solve

Selenium is open source and used by a large chunk of the testing community for automated testing of web applications. But there is a stack of technologies (HTML5/jQuery/AJAX/AngularJS etc.) involve in designing a web page which brings up many challenges for software testers using Selenium. Hence, here we come with the ten essential Selenium Webdriver howtos to address many of these real-time issues.

With every howto, there is a piece of code given to demonstrate the usage. You can use the sample code right away in your projects. Not only will it accelerate your work but help you in discussing challenges of automated web application testing during interviews. However, if you are actively looking for a job change, then read these 35 Selenium interview questions to ramp up preparation.

Before you dive in further, we must tell you that the tips here will only provide a partial solution which you can reuse in your programs. So we assume you know the basics of Selenium Webdriver. However, if you are a little out of touch, then don’t mind going through the Selenium tutorial for beginners for a quick brush up.

Let’s now open up this post with a solution to one of the most common use cases – how to automate web tables in a web application.

It is about handling the web tables where we will show how to query a table to fetch data from its cells.

The above code was just a demo before we share rest of the useful Selenium tips. Please go through the below list to see the other pieces of Selenium Webdriver howtos.

Table of Index.

  1. How to use Selenium Webdriver to click Google search?
  2. What to do when the click doesn’t work in Selenium Webdriver?
  3. How to simulate mouseover in Selenium Webdriver?
  4. How to open a URL in the new tab with Selenium WebDriver?
  5. How to use Selenium Webdriver to extract data from the PDF files?
  6. How to get element by XPath using JavaScript in Selenium WebDriver?
  7. How to select the drop down option in Selenium Webdriver?
  8. How to select all the dropdown values using Selenium WebDriver?
  9. How to get all the child of an element using Webdriver?
  10. How to get the visible text of a page with Selenium Webdriver?

10 Selenium Issues You Should Know How to Solve.

10 Most Common Selenium Webdriver Howtos

10 Selenium Webdriver Howtos.

1- How to use Selenium Webdriver to click Google search?

Since Google optimizes their CSS and JS scripts, so you can’t purely rely on using them as locators. Moreover, it adds the search links dynamically on the result page. So you have to use a smart wait for the page to show all the results.

 

2- What to do when the click doesn’t work in Selenium Webdriver?

First of all, you need to check that the element you are clicking is present on the target page. Then, you can try using the below code.

 

3- How to simulate mouseover in Selenium Webdriver?

Since it’s not realistic to achieve <mouse hover> in Selenium Webdriver but we can sequence all the actions in one go. It will give the same effect as mouseover would have.

Here is the three-line code you can use.

 

4- How to open a URL in the new tab with Selenium WebDriver?

Here is the Selenium Webdriver code snippet that will help in opening the new tab.

It’ll open the page in a new tab.

If you wish to move to the new tab, then use the below code.

 

 

5- How to use Selenium Webdriver to extract data from the PDF files?

Probably, you’ve heard it many times that you need to check a page which loads the PDF.

Here is the code to verify the online PDF file. But you first need to download the Apache PDF library.

 

6- How to get element by XPath using JavaScript in Selenium WebDriver?

Here is an easy way to retrieve the XPath using JS. Just use the JS <document.evaluate> method to fetch the XPath.

Next, you may have to call the above JavaScript function from the Webdriver code. So use the <JavascriptExecutor> as given below.

 

7- How to select the drop down option in Selenium Webdriver?

Use the following Webdriver code. It’ll help in selecting the options based on the label.

Also, you can add the below code to get the first selected value.

 

8- How to select all the dropdown values using Selenium WebDriver?

Here is the code to select all values from the drop down.

 

9- How to get all the child of an element using Webdriver?

You can query all the child of an element in Selenium Webdriver by using both the XPath and the CSS.

 

10- How to get the visible text of a page with Selenium Webdriver?

You need to run through the following steps to get the visible text.

  • Call <By.tagName(“body”)> to select the top element in the DOM.
  • Next, use the <getText()> methods on the same element. It will return the desired visible text.

 

Summary – 10 Selenium Webdriver Howtos.

You might have observed that merely reading Selenium Webdriver tutorials isn’t going to turn us into an automation geek. There are a no. of other technical things which matter and we should know as automation testers.

But most of the tutorials miss on addressing such common problems. Hence, we did a trial, researched, and rinsed the ten problems that many automation testers encounter in their work. And finally, this post on ten Selenium Webdriver howtos came through.

If you have any questions about the Selenium Webdriver howtos, then please feel free to ask them. Also, if you want to share some of yours, then let us know. We’ll get them added to this post and mention your reference there.

Keep Learning,

TechBeamers.

Leave a Reply

*