Python builds the UI automation environment

Download Python3

  • Python’s official website
  • PyCharm

Environment configuration

  • Install Python

  • Select Add Python to PATH and proceed to the next step.

  • Validation: CMD enter Python

Download Chrome Driver

  • Click to download ChromeDriver
  • Place the driver in the Python root directory

Install PyCharm

Reprint: Installation tutorial

To install Selenium

  • Open the PyCharm
  • The new Python File
  • Click Terminal at the bottom of the panel

  • Enter PIP Install Selenium installation, PIP List verification

The instance

from selenium import webdriver

# Settings: Ignore being controlled by automated testing software
option = webdriver.ChromeOptions()
option.add_argument('disable-infobars')
Instantiate the object
driver = webdriver.Chrome(chrome_options=option)
# Open url
driver.get("https://www.baidu.com")
# Navigate to the input field using the ID element and type Github
driver.find_element_by_id("kw").send_keys("github")
# Click on Baidu
driver.find_element_by_id("su").click()
driver.close()
Copy the code