Python搭建UI自动化环境
下载Python3
环境配置
- 安装Python
- 勾选Add Python to PATH,一直下一步。
- 验证:CMD输入Python
下载Chrome Driver
- 点击下载chromedriver
- 将驱动放入Python根目录下
安装PyCharm
安装Selenium
- 打开PyCharm
- 新建Python File
- 点击面板底部 Terminal
- 输入pip install selenium 安装、pip list 验证
实例
from selenium import webdriver
# 设置 :忽略正在受自动测试软件的控制
option = webdriver.ChromeOptions()
option.add_argument(‘disable-infobars‘)
# 实例化 对象
driver = webdriver.Chrome(chrome_options=option)
# 打开网址
driver.get("https://www.baidu.com")
# 通过id元素定位到输入框,输入github
driver.find_element_by_id("kw").send_keys("github")
# 点击百度一下
driver.find_element_by_id("su").click()
driver.close()
原文地址:https://www.cnblogs.com/thloveyl/p/12546177.html
时间: 2024-12-07 21:48:05