1.下载selenium
pip install selenium
2.下载驱动
选择自己浏览器对应版本
google:
https://chromedriver.storage.googleapis.com/index.html
火狐:
https://github.com/mozilla/geckodriver/releases
放到python根目录或者配置环境变量
3.获取标签
driver.find_elements(By.TAG_NAME,“button”)
By有id,tag,name,class 等
根据情况用哪个find_elements和find_element
4.等待加载
可以用
WebDriverWait(driver,timeout=10).until(EC.presence_of_element_located((By.ID,‘password’)))
也可以用
implicitly_wait(5)
5.操作
输入用send_keys(“xxx”)
点击用click()
6.退出程序
driver.quit()即可
7.隐藏程序
option=webdriver.ChromeOptions()
option.add_argument(‘headless’)
driver=webdriver.Chrome(chrome_options=option)
python自动化测试流程
最新推荐文章于 2024-05-16 22:26:33 发布