国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Selenium - Python - AttributeError: ‘WebDriver‘ object has no attribute ‘find_element_by_id‘

這篇具有很好參考價值的文章主要介紹了Selenium - Python - AttributeError: ‘WebDriver‘ object has no attribute ‘find_element_by_id‘。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

selenium:4.7.2

chromeDriver:108.0.5359.22?下載

最近看selenium遇到了這個報錯

看的是這個教程,代碼也是里面的。

from selenium import webdriver
from time import sleep

# 實例化一款瀏覽器
bor = webdriver.Chrome(executable_path='chromedriver.exe')

# 對指定的url發(fā)起請求
bor.get('https://www.jd.com/')
sleep(1)
# 進行標(biāo)簽定位
search_input = bor.find_element_by_id('key')

# 向搜索框中錄入關(guān)鍵詞
search_input.send_keys("mac pro")

# 點擊搜索按鈕
btn = bor.find_element_by_xpath('//*[@id="search"]/div/div[2]/button')
btn.click()
sleep(2)

# 執(zhí)行js,讓滾輪向下滾動
bor.execute_script('window.scrollTo(0, document.body.scrollHeight)')
sleep(2)

page_text = bor.page_source

print(page_text)

bor.quit()

報錯如下

e:\project\demo02\main.py:6: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  bor = webdriver.Chrome(PATH)

DevTools listening on ws://127.0.0.1:65430/devtools/browser/52ab5d7c-a0b0-4488-9a8c-ed83a07e7636
[25936:23208:1217/010556.344:ERROR:socket_manager.cc(138)] Failed to resolve address for stun.services.mozilla.com., errorcode: -105
[25936:23208:1217/010556.346:ERROR:socket_manager.cc(138)] Failed to resolve address for stun.services.mozilla.com., errorcode: -105
Traceback (most recent call last):
  File "e:\project\demo02\main.py", line 12, in <module>
    search_input = bor.find_element_by_id('key')
                   ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'

后來查到原因是`find_element_*`已經(jīng)被移除了

把`bor.find_element_by_id('key')`換成`bor.find_element('id','key')`就行,其他幾個類似
?

from selenium import webdriver
from time import sleep

# 實例化一款瀏覽器
bor = webdriver.Chrome(executable_path='E:/chromedriver_win32/chromedriver.exe')
# 對指定的url發(fā)起請求
bor.get('https://www.jd.com/')
sleep(1)
# 進行標(biāo)簽定位
search_input = bor.find_element('id','key')
# 向搜索框中錄入關(guān)鍵詞
search_input.send_keys("mac pro")
# 點擊搜索按鈕
btn = bor.find_element('xpath', '//*[@id="search"]/div/div[2]/button')
btn.click()
sleep(2)
# 執(zhí)行js,讓滾輪向下滾動
bor.execute_script('window.scrollTo(0, document.body.scrollHeight)')
sleep(2)
page_text = bor.page_source
print(page_text)
bor.quit()

參考:Selenium - Python - AttributeError: 'WebDriver' object has no attribute 'find_element_by_name' - Stack Overflow文章來源地址http://www.zghlxwxcb.cn/news/detail-516752.html

到了這里,關(guān)于Selenium - Python - AttributeError: ‘WebDriver‘ object has no attribute ‘find_element_by_id‘的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包