Web自动化测试(Selenium工具 注意浏览器版本和驱动版本要一致)
环境部署
pip3 install selenium
安装chrome-browser
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm --no-check-certificate
sudo yum install google-chrome-stable_current_x86_64.rpm
安装chromedriver:一个用来和chrome交互的接口
sudo yum install chromedriver
浏览器
谷歌浏览器
http://chromedriver.storage.googleapis.com/index.html?path=2.37/
import time
from selenium import webdriver
chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"
driver = webdriver.Chrome(chromedriver)
driver.get("http://www.baidu.com")
time.sleep(3)
driver.find_element_by_id("kw").send_keys("selenium软件自动化测试开发")
time.sleep(3)
driver.find_element_by_id("su").click()
time.sleep(3)
driver.quit()
print("Done!")
time.sleep(3)
火狐浏览器
https://github.com/mozilla/geckodriver/releases
import time
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://www.baidu.com")
time.sleep(3)
browser.find_element_by_id("kw").send_keys("魔都大上海")
time.sleep(3)
browser.find_element_by_id("su").click()
time.sleep(3)
browser.quit()
time.sleep(3)
posted on 2019-03-01 13:58 Indian_Mysore 阅读(858) 评论(2) 编辑 收藏 举报