selenium 报错

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() #关闭浏览器

成功啦

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值