selenium 属性错误:'WebDriver'对象没有'find_element_by_xpath'属性

ff29svar  于 2022-12-04  发布在  其他
关注(0)|答案(3)|浏览(424)
from selenium import webdriver
import time

test = webdriver.Chrome()
test.get('https://docs.google.com/forms/d/e/1FAIpQLSeYUmAYYZNtbU8t8MRxwJo-        d1zkmSaEHodJXs78RzoG0yFY2w/viewform')

time.sleep(5)

Name = 'kuch bhi'
last = test.find_element_by_xpath('//*[@id="mG61Hd"]/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[1]/div/div[1]/input')
last.send_keys(Name)

当我执行代码的时候,我得到一个错误消息,
属性错误:'WebDriver'对象没有'find_element_by_xpath'属性

bq3bfh9z

bq3bfh9z1#

Selenium刚刚在4.3.0版本中删除了该方法。请参阅更改:https://github.com/SeleniumHQ/selenium/blob/a4995e2c096239b42c373f26498a6c9bb4f2b3e7/py/CHANGES

Selenium 4.3.0
* Deprecated find_element_by_* and find_elements_by_* are now removed (#10712)
* Deprecated Opera support has been removed (#10630)
* Fully upgraded from python 2x to 3.7 syntax and features (#10647)
* Added a devtools version fallback mechanism to look for an older version when mismatch occurs (#10749)
* Better support for co-operative multi inheritance by utilising super() throughout
* Improved type hints throughout

您现在需要用途:

driver.find_element("xpath", '//*[@id="mG61Hd"]/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[1]/div/div[1]/input')

在您的示例中,可以用途:

last = test.find_element("xpath", '//*[@id="mG61Hd"]/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[1]/div/div[1]/input')

为了提高可靠性,应考虑将WebDriverWaitelement_to_be_clickable结合使用。

ljsrvy3e

ljsrvy3e2#

您现在可以用途:

from selenium.webdriver.common.by import By

driver.find_element(by=By.XPATH, value='//<your xpath>')
rseugnpd

rseugnpd3#

从selenium.webdriver.common导入的所有匹配项

相关问题