特殊说明:自动化测试工具必须安装驱动程序,否则会报错:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
谷歌驱动下载:https://sites.google.com/a/chromium.org/chromedriver/home
驱动版本不匹配错误【最新版的驱动必须匹配最新版的谷歌浏览器】:
This version of ChromeDriver only supports Chrome version 81参考:http://www.codingwhy.com/view/5188.html
谷歌浏览器参考别人写的:https://www.cnblogs.com/yoyoketang/p/8078873.html
selenium 获取某个元素的html【如何支持获取伪元素:: before中的content内容】https://blog.csdn.net/weixin_43343144/article/details/106469298
谷歌浏览器后台启动配置方法
# 配置谷歌浏览器静默启动【后台启动】
chrome_options = webdriver.ChromeOptions()
# 谷歌浏览器headless前面的--可以不加【建议加上,代表命令行参数】
chrome_options.add_argument('--headless')
# 一定要把chrome_options配置来构造谷歌浏览器对象【必须匹配对应驱动的路径】
web_chrome = webdriver.Chrome(executable_path=r"D:\www\KirinProject\path\chromedriver.exe",options=chrome_options)
web_chrome.get("https://www.baidu.com")
print(web_chrome.page_source)
火狐浏览器后台启动配置方法:
from selenium import webdriver
firefox_options = webdriver.FirefoxOptions()
# 注:火狐浏览器headless前面一定要加--,代表命令行参数
firefox_options.add_argument('--headless')
webdriver.FirefoxOptions()
web_firefox = webdriver.Firefox(options=firefox_options)
web_firefox.get("http://www.baidu.com")
print(web_firefox.page_source)
其他浏览器原理差不多!