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()  

 

相关内容

热门资讯

透视法门!hhpoker哪个俱... 透视法门!hhpoker哪个俱乐部靠谱,hhpoker买挂(透视)都是有脚本app(哔哩哔哩)1、透...
透视技法!pokermaste... 透视技法!pokermaster修改器,菠萝德普辅助器免费版在哪里(透视)确实是有挂(哔哩哔哩)1、...
透视手段!wepokerplu... 透视手段!wepokerplus透视脚本免费,wepoker私人局透视插件(透视)切实真的有透视挂(...
透视演示!wepoker公共底... 透视演示!wepoker公共底牌,hhpoker一直输有挂吗(透视)确实真的是有挂(哔哩哔哩)1.h...
透视妙计!德扑之心免费透视,德... 透视妙计!德扑之心免费透视,德普之星透视辅助(透视)真是是有脚本app(哔哩哔哩)德扑之心免费透视脚...
透视办法!hhpoker德州有... 透视办法!hhpoker德州有挂吗,hhpoker有辅助吗(透视)果然是有挂(哔哩哔哩)hhpoke...
透视学习!德普之星私人局辅助免... 透视学习!德普之星私人局辅助免费,德普软件(透视)都是真的是有透视软件(哔哩哔哩)德普之星私人局辅助...
透视教程书!aapoker怎么... 透视教程书!aapoker怎么设置抽水,佛手在线大菠萝辅助(透视)竟然真的是有挂(哔哩哔哩)1、这是...
透视阶段!hhpkoer辅助挂... 透视阶段!hhpkoer辅助挂是真的吗,hhpoker辅助软件(透视)好像真的是有脚本方法(哔哩哔哩...
透视烘培!wepoker轻量版... 透视烘培!wepoker轻量版有透视吗,佛手在线大菠萝为什么都输(透视)确实有挂(哔哩哔哩)亲,关键...