1. Download Python
Python Release Python 3.8.0 | Python.org
My computer is 64-bit, download the corresponding file.
Enter cmd (windows command prompt) and enter the "Python" command.
(If you are prompted that python is not an internal or external command! Don't worry, go configure the environment variables)
Modify the PATH in My Computer -> Properties -> Advanced -> Environment Variables -> System Variables to:
Variable name: PATH
Variable value: ;C:\Python38;C:\Python38\Scripts;
2. Install selenium
install via pip
C:\Users\fnngj>pip install selenium
Download the specified version: pip install selenium==3.141.0
Warning when installing library using pip
Prompt that the current version of pip is too low, use the command to install the specified version of pip
python -m pip install pip==22.0.4
After updating pip, to reinstall selenium: pip install selenium
3. Install the Chrome driver
The version of chromedriver must be consistent with the version of Chrome, otherwise it will not work.
The download address of the chrome driver is here.
https://chromedriver.storage.googleapis.com/index.html
Download and unzip, you will get a chromedriver.exe file, put it in the chrome installation directory. ...\Google\Chrome\Application\ , and then set the path environment variable, add the chrome installation directory to the variable, you need to put the chromedriver.exe file in the python installation directory.
You can test that it was added correctly by starting the driver:
If the above is configured correctly, you will see some output related to driver startup
4. pycharm installation
Finally, open pycharm, add this module, and you can use it.
file- setting
Five: The first automated test script
from selenium import webdriver import time def main(): b = webdriver.Chrome() b.get('https://www.baidu.com') time.sleep(5) b.quit() if __name__ == '__main__': main()