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

成功啦

最近更新

  1. TCP协议是安全的吗?

    2023-12-22 00:38:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-22 00:38:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-22 00:38:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-22 00:38:03       18 阅读

热门阅读

  1. MySQL_15.UNDO和REDO的区别

    2023-12-22 00:38:03       33 阅读
  2. 【AI】YOLO学习笔记二

    2023-12-22 00:38:03       29 阅读
  3. JVM中的虚拟机栈的动态链接部分存放到底是什么

    2023-12-22 00:38:03       35 阅读