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

成功啦

  • 20
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
引用提供了关于安装python和selenium的步骤和错误信息。在安装selenium时,您遇到了pip的错误。要解决这个问题,您可以尝试以下方法: 1. 确保您使用的是最新版本的pip。您可以使用以下命令升级pip: `pip install --upgrade pip` 2. 检查您的网络连接是否正常,并尝试使用以下命令安装selenium: `pip install selenium` 3. 如果您的网络连接存在问题,您可以尝试使用本地安装包进行安装。您可以在selenium官方网站上下载适用于您的操作系统的安装包,并使用以下命令进行安装: `pip install /path/to/selenium-3.12.0.tar.gz` 引用提供了关于Selenium元素定位和点击报错的信息。您遇到了ElementClickInterceptedException错误。为了解决这个问题,您可以尝试以下两种方式: 1. 使用execute_script方法执行JavaScript代码来点击元素: ```python element = driver.find_element_by_xpath("表达式") driver.execute_script("arguments[0].click();", element) ``` 2. 使用ActionChains类来模拟鼠标操作来点击元素: ```python from selenium.webdriver.common.action_chains import ActionChains element = driver.find_element_by_xpath("表达式") ActionChains(driver).move_to_element(element).click(element).perform() ``` 引用提供了关于chromedriver路径问题的解决方案。您遇到了'chromedriver' executable needs to be in PATH错误。为了解决这个问题,您可以按照以下步骤进行操作: 1. 访问http://chromedriver.storage.googleapis.com/index.html,找到与您的Chrome浏览器版本相对应的chromedriver.exe下载链接,并下载对应版本的chromedriver.exe。 2. 解压下载的文件,并将chromedriver.exe文件放置在Chrome浏览器的安装目录下。 3. 将chromedriver所在目录添加到系统的PATH环境变量中。 以下是示例代码,展示了如何使用已安装的chromedriver: ```python from selenium import webdriver url = "http://www.baidu.com" browser = webdriver.Chrome(executable_path="C:\Users\12717\AppData\Local\Google\Chrome\Application\chromedriver.exe") browser.get(url) ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值