Sign in

Software Engineer, Python Enthusiast, Darbuka Player,

Links to all posts in the series

Photo by Joshua Sortino on Unsplash

How to control your automation on a remote machine

Photo by Possessed Photography on Unsplash

In the previous post, we looked at the usage of Selenium with the unittest module. We will see how to use WebDriver remotely in this last post of the series.

Until now, we executed our automation scripts locally. You can also use WebDriver remotely the same way you would use it locally. With this type of work, you can keep your scripts on your machine and set up a remote machine to run your scripts.

A remote WebDriver is composed of two pieces: a client and a server. The client is your code and the server is a Java servlet.

How to use Selenium with Python’s unittest

Photo by Christina Morillo from Pexels

In the previous post, we explored the page object model for writing a more maintainable and reusable code. We will see the usage of Selenium with Python’s unittest module in this post.

Unit tests are used to test the smallest testable parts of a program. Python’s unit testing framework provides test management features like setting pre/postconditions, checking the result with the expected output, and generating a report of test executions.

unittest module consists of five functionality

  • Test Loader: Loads test cases and suites.
  • Test Case: Implements the interface needed by the test runner.
  • Test Suite: Groups set of test cases.

Page Object Model for better structured and maintainable code

Photo by Christina Morillo from Pexels

In the previous post, we explored managing window position and dimensions and also taking screenshots with Selenium. We will see Page Object Model(POM) to create more structured and maintainable code in this post.

Until now, we have used mostly functions and single modules for our examples. If you try to manage a web page with lots of pages or components with a wide range of interactions among them, things might get complicated with this approach.

This is a general problem and as always there is a common solution for this common problem with a design pattern called “Page Object Model”.

Managing windows and taking screenshots

Photo by Kyle-Philip Coulson on Unsplash

In the previous post, we looked at controlling mouse actions. We will see how to manage window position and dimensions and also take screenshots in this post.

In part 6 of this series, we explored window handles and switching between windows. This post will complete the window related discussion mostly.

Window Management

Screen resolution can impact how web applications render, so Selenium WebDriver provides mechanisms for moving and resizing the browser window.

get/set window size

get_window_size retrieves the size of the browser window in pixels as a dictionary with width and height keys.

width = driver.get_window_size().get("width")
height = driver.get_window_size().get("height")

set_window_size restores the window and sets…

How to control the mouse

Photo by Deepal Tamang on Unsplash

In the previous post, we looked at working with select elements. We will look at controlling the mouse actions in this post.

We had briefly looked at some mouse actions in the Keyboard and Action Chains post. We will use action chains in the examples throughout this post too.

Selenium enables us to emulate all kinds of mouse actions like a double-click, right-click, mouse over, drag&drop, etc. These actions performed with the help of ActionChains class.

Every action called on the ActionChains object is stored in a queue and executed in order with the perform call. …

How to interact with select elements

Photo by Glenn Carstens-Peters on Unsplash

In the previous post, we looked at how to manage different kinds of alert dialogs. This post will be about working with select elements on a web page.

The <select> tag is used to create a drop-down list of options. It is usually used in a form to collect user input.

Selenium provides a Select class in the support package to manage select elements easily.

In order to start, we need to create a Select instance with a select element. If you don’t give an element with the select tag, UnexpectedTagNameException is raised.

from import Select# ...element…

How to handle alert dialogs

Photo by Anna Tarazevich from Pexels

In the previous post, we looked at working with cookies. We will explore the handling of alert dialogs in this post.

An alert is a pop-up window. It gets triggered due to some action performed by the user or automatically due to some system settings. Their purpose is to give some information to the user, take permission, or take some input from the user.

Selenium WebDriver Alert API provides methods to handle interactions with these pop-up message boxes.

We can categorize the alerts into the following three types:

  1. Simple Alert
  2. Confirmation Alert
  3. Prompt Alert

Simple Alert

A simple alert shows a custom…

How to manage cookies with Selenium

Photo by Jade Wulfraat on Unsplash

In the previous post, we looked at how to execute JavaScript code with the help of Selenium. We will explore cookie management in this post of the series.

What is a cookie and what are they used for? Cookies are key-value pairs followed by zero or more attribute-value pairs stored on the client-side. It is a small piece of data sent from the web application and stored in the web browser, while the user is browsing that web page. They usually store information about users, their preferences, and past activities. …

How to execute JavaScript code with Selenium

Photo by Irvan Smith on Unsplash

In this post, we will look at how to execute JavaScript code on the page with Selenium.

Document Object Model(DOM) can access and manipulate all the elements on a web page with JavaScript. You can inspect an element on a web page and see the available methods using developer tools of your browser of choice. You can run JavaScript code with Selenium if a certain action can not be performed using regular Selenium commands.

To accomplish this, Selenium WebDriver will inject the JavaScript statement into the browser and the script will perform the job.

There are two methods for the…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store