测试-selenium学习|报错 :DeprecationWarning: executable_path has been deprecated, please pass in a Servic

在使用selenium的时候运行如下代码的时候报出错误 :DeprecationWarning: executable_path has been deprecated, please pass in a Service object

查询得知:
“出现 DeprecationWarning 警告的类型错误:该类型的警告大多属于版本已经更新,所使用的方法过时。

当前版本重构后的函数,是之前的 executable_path 被重构到了 Service 函数里”
原文解释:点击跳转

源代码:
from selenium import webdriver
import time

webdriver 获取浏览器对象

driver = webdriver.Chrome(“chromedriver.exe”)

准备一个网址

http://www.baidu.com

url=“http://www.baidu.com”
driver.get(url)

查找元素

driver.find_element(value=“kw”).send_keys(“美女”)

回收资源

time.sleep(10)
driver.quit()

#增加Service导入:
from selenium import webdriver
import time
from selenium.webdriver.chrome.service import Service

s=Service(“chromedriver.exe”)
driver = webdriver.Chrome(service=s)

准备一个网址

http://www.baidu.com

url=“http://www.baidu.com”
driver.get(url)

查找元素

driver.find_element(value=“kw”).send_keys(“美女”)

回收资源

time.sleep(10)
driver.quit()

问题解决,值得注意的是定位元素的输入方式。
driver.find_element(value=“kw”).send_keys(“美女”)

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值