This article mainly explains how to build a selenium environment in the Mac environment. The author is also a beginner in testing. He is currently ignorant of selenium. He hopes to gradually understand it starting from the construction of the environment.
Environmental preparation
The environment used in this article:
• Python 3.7.3
PS: The
Mac environment will have its own Python environment by default, but the Python2 version, so if you want to use the Python3 environment, you need to install it yourself. Because I have not configured the environment, if I need to use the Python3 environment in the terminal, I need to enter python3 xxx, otherwise, if it is python xxx, it will be the default python2 version.
• IDE PyCharm CE
Building steps
- Install Python3 environment
- Install selenium
• pip3 install selenium
There is a warning here that the pip3 command needs to be upgraded (pip is a command used to install and maintain Python packages),
so you can upgrade through pip3 install --upgrade pip - Install the driver WebDriver corresponding to the browser
• Different browsers correspond to different drivers, the author uses Chrome here, and the current Chroem version is 84.0.4147.135 (because the exact same version number was not found, here we use it until the secondary version corresponds try)
• ChromeDriver download address: https://chromedriver.storage.googleapis.com/index.html
• After downloading, resolve the file, you will see a ChromeDriver.exe file, move it to /usr/local /bin path
Here you can either move after the command, or directly open the corresponding directory to move.
Command line form:
mv xxx file moved directory
Direct drag:
The /usr/local directory under Mac is hidden from Finder by default. If you need to go to /usr/local, open Finder, and then use command+shift+G to pop up Fill in /usr/local in the directory. - Create a new file in pyCharm to verify that the configuration is successful
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get('http://www.baidu.com')
print("Selenium Test.")
time.sleep(6)
driver.quit()
print("Time's up. Already quit.")
After running, you can open the Chrome browser and visit the Baidu homepage, print the Selenium Test. Close Chrome after waiting for 6 seconds.
If you are interested in software testing, want to know more about testing knowledge, solve testing problems, and get started guidance to help you solve the confusion encountered in testing, we have technical experts here. If you are looking for a job or have just graduated from school, or have already worked but often feel that it is very difficult, feel that you are not good enough in the test, want to continue your studies, or want to change careers and are afraid that you will not be able to learn, you can join us
. Get the latest software testing factory interview materials and Python automation, interface, framework construction learning materials!
At this point, Selenium configuration is successful.