Below is my cheat sheet for Selenium. I'm using Python đ, but the concepts are the same for the rest of the languages. I use Endtest to quickly create Automated Tests and execute them on the cross-browser cloud. You should check out the docs. This cheat sheet has examples on common methods used in Selenium Automation. Suggestion is to learn Core Java before moving to Selenium Automation. If you already know Java then Selenium is peanut for you. Although Selenium supports various programming languages (C#, Java, Perl, PHP, Python & Ruby etc.) but this cheat sheet has exmples using only Java. Hi Jyotsana, you can manually set proxy settings of a browser using Python Selenium Webdriver this way: from selenium import webdriver from selenium.webdriver.common.proxy import Proxy, ProxyType prox = Proxy prox.proxytype = ProxyType.MANUAL prox.httpproxy = 'ipaddr:port' prox.socksproxy = 'ipaddr:port' prox.sslproxy = 'ipaddr:port' capabilities = webdriver.DesiredCapabilities.CHROME. The thing that I felt that is missing in the materials was a sheet containing all of the most relevant code snippets. If you google it, you will find several similar cheat sheets (Java, Python), but the C# one was missing. So I decided to fill that gap. So, I created the first and most complete Selenium WebDriver C# cheat she et. Selenium WebDriver Cheat Sheet Cheat Sheet. Selenium WebDriver Code Examples in Java Programming (Helpful to refer this sheet before attending Interviews) https.
Acceptance tests are an important final step to take when releasing anything you may have designed, to make sure that the software you have created meets the requirements and specifications laid out when you designed and planned your application or platform. Automated testing is an integral tool to use to efficiently and accurately test your product for release.
In order to write automated web tests that are easy to maintain, perform well, and are ultimately resilient, there are some simple guidelines to follow:
- Write atomic and autonomous tests
- Group like tests together in small batches
- Be descriptive
- Use a Test Runner
- Store tests in a Version Control System
Grouping Tests
As your test suite grows, you will have numerous test files. Each file contains a group of tests that have similar functions. For example, you would have one directory for the files that are designed to locate and interact with the page, and another directory for files that perform tests (test to check if something does or does not happen when you interact).
Test Runners
At the heart of every test suite is some kind of a test runner like Mocha that does a lot of the heavy lifting such as test execution, centralized configuration, and test output. In this course, we will be using the Mocha test runner. Rather than reinvent the wheel, you can use one of the many test runners that exist today. With it you can bolt on third party libraries to extend its functionality if there's something missing.
BDD and TDD
Behavior Driven Development and Test Driven Development are two important strategies to help you understand how to write effective tests. BDD is a collaborative process that focuses on starting with a business value or need. It's a feature and epic-centric approach to create a requirements analysis. With both BDD and TDD, you plan to write the code for the test first (application code comes later).
TDD is a more granular step that should be taken after a BDD plan is created. The general process involves writing a failing test for particular features (determined previously with the BDD process), then the developer writes the code to lead to a successful run of this test. The goal is to be able to write failing tests that can be turned into a passing test with minimal code modification, and no change to dependencies, base pages, or configuration files.
Here you will learn how to control any browser application with a little Python and selenium. You can use this for creating your own Instagram Bot for example. We start with a few basics and end with a cheat sheet summarizing the most important code snippets. Letâs go!
One way to automate the tasks that are performed in the browser is to use a program that ârecordsâ your activities on the website and can play them back as often as you like. No coding is needed for this. Correspondingly stupidly the program executes its steps.
You can find a Chrome extension here, that allows you to record and play your tasks. Now this works for logging into Instagram well, but we need some kind of programming to make our automation a bit smarter.
Below I have added an example of how such a login via Selenium might look like. He notes all necessary HTML IDs to be able to access them directly later. If Instagram should change the IDs at a later time, the user will surely not notice it. The bot will still not find the individual parts again and will fail.
First of all. We will not directly control the browser. We will write a script that uses a web driver to control a browser. For example, our Python script will use a ChromeDriver to control the web browser Google Chrome.
So we need Selenium and a Webdriver.
- Selenium: You can install selenium via âpip3 install seleniumâ inside for example Powershell.
- Webdriver: You can download it from the SeleniumHQ Website for your preferred Browser.
When using the program, you can set the path to the driver like this (Old way):
Selenium Python Cheat Sheet Pdf
There is a better way to start. Create a new python Script and let it download and set chromedriver by itself. For that, we need âwebdriver managerâ:
Is this installed, you can now create a little Python file and run it to open a specific Website. In my case Instagram:
You can see the whole HTML Code right inside the Browser. Just right click and click âinspectâ. You can also press âCtrl + Shift + Iâ. You can use this to see all the IDs and points we will use to automate.
In Python, you now can use the âdriver.find_elementâ to address exactly one spot. By their specific name or class or ID. Whatever suits you the most:
Selenium Webdriver Commands
In my case, the Button doesnât have any ID. So I have to target it via the âXPathâ and search for the text inside the button. Each element has its own path. We can either search using the absolute path, which would result in errors if we changed the website structure. Or we search within our specified path for a word. Here the structure of the website can change as much as it wants, our word is always found.
In our case, itâs the word ânextâ. This way we can make sure that we notice when Instagram changes something as soon as possible because you have to change it so that it is changed for the user.
How to find your XPath and use it inside your Script
You now can find and click the button via the text the user can see, or via the XPath, you have copied above. The following Script will open Instagram, and waits 5 seconds till it clicks the Next Button. Of course, it wonât log in, because there is no data typed in.
xxx will be your variable which contains the XPath or name. In our Example above it would be âpython_buttonâ.

| Radio Button | xxx.click() |
| Click Checkbox | |
| Click Button | |
| Textfield | xxx.send_keys(âHello World!â) |
| Getting Text | xxx.get_attribute(âtextâ) |
| Dropdown by visible text | xxx.select_by_visible_text(âGermanyâ) |
| Dropdown by value | xxx.select_by_value(â1â) |
