Recently, someone from a local freelancing platform asked me to write a program to click ads for a given search query on Google. I sent him a sample but he decided not to buy it, so I decided to publish it here.
It uses the Tor network to change the IP address and Selenium with Python bindings for browser automation.
You can follow the steps manually from this gist to set up Tor or use the following script to set up both virtual environment and Tor.
You should see the following output at the end of the run.
Links to all posts in the series
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.
In this post, I will share an automation on YouTube to search for a query, sort results by view count, and take screenshots of the top three results.
We need to create a virtual environment before starting to isolate dependencies from the rest of the system.
Run the following commands according to your dependency management way. You can find the Pipfile or requirements.txt files here on the project page.
python -m venv env
pip install -r requirements.txt
After the environment setup is completed, we…
I am working as a software engineer for about 7 years. I usually worked with C++ on old, embedded systems.
I still feel insufficient what I work on most of the time. I wanted to list the difficulties I have through these years working on platform-dependent projects.
Project codebases I worked on were large enough not to learn and feel in control quickly. It is hard to add new code/features especially if the code is poorly documented in big and old projects.
Refactoring is even harder because the possibility of breaking somewhere you don’t expect or even don’t know it…
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
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”.
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.
Screen resolution can impact how web applications render, so Selenium WebDriver provides mechanisms for moving and resizing the browser window.
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…
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. …
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.
<select> tag is used to create a drop-down list of options. It is usually used in a form to collect user input.
In order to start, we need to create a
Select instance with a select element. If you don’t give an element with the
UnexpectedTagNameException is raised.
from selenium.webdriver.support.select import Select# ...element…