Sign in

Software Engineer, Python Enthusiast, Darbuka Player, https://coskundeniz.github.io/

How to click ads with different IPs.

Photo by Pixabay from Pexels

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.

How to Setup Environment and Tor

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.

...
Enabling…


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.


Search, sort, and screenshot on YouTube

Photo by Christian Wiediger on Unsplash

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.

Prepare Your Environment

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.

  • If you are using pip
python -m venv env
source env/bin/activate
pip install -r requirements.txt
  • If you are using pipenv
pipenv shell
pipenv install

How to Implement

After the environment setup is completed, we…


It was a pain. It still is …

Photo by Elisa Ventur on Unsplash

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.

1. Development/Refactoring

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…


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. …

Coşkun Deniz

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