The LEAP

Automation insights and productivity tips from LEAPWORK.

All Posts

How to Use Iteration in Web Automation

A demonstration of how to iterate through found content with LEAPWORK's Selenium-based web automation capabilities.

While we're working our way towards our early access launch of Selenium support in LEAPWORK, I wanted to show off a couple of interesting details. But before I do, let me just preface it by saying that this post is aimed at testers who are familiar with HTML and CSS as well as some of the problems typically faced when working with Selenium.

The new "web" building blocks have been designed to look and feel just like the existing image and text recognition blocks to make you as productive as possible when dealing with Selenium. One similarity is the ability to "Use all occurrences", which is an implicit way of iterating or looping over found content.

In this short demonstration video, I load up the highly popular social networking site reddit.com, where users give articles and comments "karma points" by voting on them. I then find all articles with more than 40.000 karma points and get the title for each one.

 



As you can see, the whole thing took only a few minutes to make from scratch, using six building blocks. It shows how relatively easy it is to fluently navigate hierarchical structures in HTML pages without writing a single line of code.

Speaking of code, I also sat down and tried to write the same test in Selenium with C#. I enjoy writing code tremendously -- ask anyone who knows me -- but even for something as simple as this test case, it still took about 20 minutes to fiddle with XPath statements and doing a bunch of trial-and-error runs.

Here's what the code looks like:

ChromeDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://reddit.com/"); var scoreDivs = driver.FindElementsByCssSelector(".score.unvoted");
foreach (var scoreDiv in scoreDivs)
{
if (scoreDiv.Text.EndsWith("k"))
{
var score = Convert.ToDecimal(scoreDiv.Text.Substring(0, scoreDiv.Text.Length - 1), new CultureInfo("en-US"));
if (score > 40)
{
var postDiv = scoreDiv.FindElement(By.XPath("./../.."));
var titleDiv = postDiv.FindElement(By.XPath(".//a[contains(@class, 'title')]"));
var title = titleDiv.Text;
Console.WriteLine(score + "k: " + title);
}
}
}

 

driver.Close();
driver.Quit();

I think this demonstration is a nice preview of some of the upcoming things, but we've only just scratched the surface. We're right now working hard on improving the user experience of our Selenium support in LEAPWORK and optimizing performance to make it even easier and faster to use.

[DOWNLOAD] Automation Tools Comparison

Whether you are already automating test cases, or you are new to the field, it is important to select the right tool. We have made a  comparison of the most common tools within the field of test automation: 

Download Test Automation Tools Comparison

Everything you need for codeless web automation

Dig deeper into web automation with the LEAPWORK guide on everything you need to know to automate web-based tests and processes.

Claus Topholt
Claus Topholt
CTO and co-founder of LEAPWORK.

Related Posts

Can You Use Selenium Webdriver for Regression Testing?

There are countless automated regression testing tools for web applications on the market. One of the most popular ones is Selenium Webdriver. In this post, we’ll take a look at Selenium and help you evaluate if it’s the right tool for you and your testing team.

How to Make Automation of Regression Testing Cost-Effective

Regression testing is a time-consuming, yet critical, part of testing and quality assurance. This is why many try to automate their regression testing suite. But setting up automation can, in and of itself, be a time-consuming and costly affair, often diminishing the positive effects of automation.

Regression Test Automation Strategy in 8 Steps

You’re probably here because you’ve decided to automate your regression tests. So far so good. But how will you get started? What should you consider? Should you just jump straight into it or take a strategic approach and prepare yourself for the project that lies ahead? Consider the 8 points outlined in this guide and you’ll probably know the answers to these questions by then.