Selenium问题解决记录:AttributeError: ‘WebDriver‘ object has no attribute ‘find_element_by_id‘
创始人
2024-09-25 02:21:35
0

1. 问题:

        在selenium元素定位时,出现报错AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'

2.原因:

        由于版本迭代,Selenium在4.3.0版本中移除了find_element_by_*,新版的selenium已经不再使用find_element_by_id方法。

3. 解决办法:

将根据元素定位方式的元素改为大写

实只需要把原来代码中的元素定位方式改成需要的方式,by+后面大写,把_改成.(PS:一定要大写)

eg:
报错代码:
button = browser.find_element_by_id('kw')
修改后的代码:

        将button = browser.find_element_by_id('kw')修改为如下语句button = browser.find_element(By.ID,'kw')

button = browser.find_element(By.ID,'kw')

        再在其代码页的最前端添加下列代码

from selenium.webdriver.common.by import By

4.代码及运行实例

#  #coding=utf-8  from selenium.webdriver.common.by import By  #引用'webdriver'模块 from selenium import webdriver  #  import time  def main():     #引用谷歌浏览器     b = webdriver.Chrome()     b.get('https://www.baidu.com')     #执行后,输入字符“Selenium”     b.find_element(By.ID, "kw").send_keys("Selenium")     time.sleep(5)     b.quit()  if __name__ == '__main__':     main()  

 

相关内容

热门资讯

透视玄学!wepoker有辅助... 透视玄学!wepoker有辅助工具吗,we-poker有人玩吗,练习教程(本来是有挂)-哔哩哔哩we...
截至目前!微乐小程序微乐房间怎... 截至目前!微乐小程序微乐房间怎么开挂,决战十水三辅助,可靠教程(都是是有挂)-哔哩哔哩1、微乐小程序...
透视安卓!hhpoker德州透... 透视安卓!hhpoker德州透视挂(透视)开挂辅助软件(其实是真的挂)-哔哩哔哩1、hhpoker德...
透视计算!hhpoker万能辅... 透视计算!hhpoker万能辅助器,hhpoker的辅助是真的吗,诀窍教程(果然存在有挂)-哔哩哔哩...
现有关情况通报如下!哈灵脚本辅... 现有关情况通报如下!哈灵脚本辅助,潮汕木虱有辅助挂吗,辅助教程(一直真的是有挂)-哔哩哔哩1、让任何...
透视辅助器!pokerrrr2... 透视辅助器!pokerrrr2辅助(透视)开挂辅助挂(确实是真的挂)-哔哩哔哩一、pokerrrr2...
今日!玖游卡五星辅助,微信微乐... 今日!玖游卡五星辅助,微信微乐辅助免费,可靠教程(确实是有挂)-哔哩哔哩1、操作简单,无需注册,只需...
透视苹果版!wepoker正确... 透视苹果版!wepoker正确养号方法,德普之星透视辅助软件是真的吗,阶段教程(好像存在有挂)-哔哩...
透视德州!werplan脚本(... 透视德州!werplan脚本(透视)开挂辅助工具(果然是有挂)-哔哩哔哩一、werplan脚本AI软...
经核实!指尖四川辅助脚本,小闲... 经核实!指尖四川辅助脚本,小闲川南怎么辅助,安装教程(本来是真的挂)-哔哩哔哩1、经核实!指尖四川辅...