Hello! I'm Takahashi, I joined the development department just recently.
It's been about two weeks since we started our automation work. Every time I go forward, I hit a wall, and I am struggling every day.
In this article.Python and SeleniumI will write about the environment construction and basic usage to operate Chrome using
Click here for table of contents
- 1. what is Selenium?
- 2. environment construction
- 3. let's actually move it!
What is Selenium?
Selenium is a browser automation tool. It allows you to test the behavior of your website by automatically manipulating the browser.
Screen operations such as clicking, keyboard input, and screen information acquisition can be performed automatically.
▼ According to the official Selenium.dev website (English only)
Primarily it is for automating web applications for testing purposes, but is certainly not limited to just that.
Boring web-based administration tasks can (and should) also be automated as well.
and is the de facto standard tool for test automation of web applications.
In addition to testing, the main uses of the software are task automation and website crawling.
It also works well with Python, which seems to be a standard combination for those who don't have much programming experience but want to automate tests.
In order to use Selenium to automatically manipulate the browser, you need to install the following
- web browser
- ┗Chrome, Firefox, IE, Opera etc.
- A module that exposes an API for manipulating the┗ browser.
- A library that communicates with the┗ WebDriver and manipulates the browser from the program
In this section, I'll show you how to create an environment for using Selenium with Python directly on your local PC.
Build the environment locally
This section describes how to set up an environment for running Selenium locally on Windows.
This is the configuration for this method.
note (supplementary information) symbolFrom Selenium official website
The browser and WebDriver are all running locally, and Selenium connects to the local driver.
Check your Chrome version
To decide which version of WebDirver to install, check the version of Chrome you have installed. In my environment
87.0.4280.66 had been installed.
Download the WebDriver binary for Chrome.
Go to the following site and download the binary of the driver closest to your browser version
Install the Python Selenium Binding
The Python Selenium bindings are installed with pip.
$ pip install selenium
I'll move it.
In a local environment, you can run Selenium with code like the following
Import #webdriver from selenium import webdriver 1Configure the options of TP3T WebDriver options = webdriver.ChromeOptions() options.add_argument('--headless'.) print('connectiong to remote browser...') Chrome = webdriver.Chrome(executable_path=r "your/path/to/chromedriver.exe") driver = Chrome driver.get('https://python.org') print(driver.current_url) # Close the browser driver.quit()
Running the above code will launch Chrome on your PC.
options.add_argument('--headless') part is commented out, you can see the browser screen and confirm that it is working.
Now that we're ready to build an environment for using Selenium, let's see how we'll actually use it.
What I want to do.
Now, let's run Chrome with Selenium and do the following
- Accessing the toppage search bar on Python.org
- Type "list" in the search bar and click the "Go" button
- Learn the "list comprehension" link on the destination page.
Running Selenium in Python
The above is a brief overview.
In my next post, I'll explain the details of the code I wrote above.