selenium 报错
开始学自动化测试,,环境配了一天TAT
安装好selenium之后
运行python脚本
# coding=utf-8
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
time.sleep(3)
driver.quit()
疯狂报错
selenium.common.exceptions.NoSuchDriverException: Message: Unable to
obtain driver for chrome using Selenium Manager.; For documentation on
this error, please visit:
https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location
网上查了一下,没找到有用的
都是driver = webdriver.Chrome(Chromedriver地址)
因为selenium升级了我的是4.16
这里定义已经改了
所以通过service来传地址
from selenium.webdriver.edge.service import Service
ser = Service()
ser.path = r'D:\useful\python3\chromedriver.exe'
driver = webdriver.Chrome(service=ser)
报错2
urllib3.exceptions.ProxySchemeUnknown: Proxy URL had no scheme, should start with http:// or https://
不知道啥原因,我也没开代理
google搜到再加一个这个
from selenium.webdriver.chrome.options import Options
opts = Options()
opts.ignore_local_proxy_environment_variables()
总的代码
# coding=utf-8
from selenium import webdriver
import time
from selenium.webdriver.edge.service import Service
from selenium.webdriver.chrome.options import Options
opts = Options()
opts.ignore_local_proxy_environment_variables()
ser = Service()
ser.path = r'D:\useful\python3\chromedriver.exe'
driver = webdriver.Chrome(options=opts,service=ser)
driver.get("https://www.baidu.com") # 打开百度浏览器
time.sleep(3) #等待3秒
driver.quit() #关闭浏览器
成功啦