fir*_*r47 75 selenium browser-automation python-3.x selenium-chromedriver selenium-webdriver
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)
Run Code Online (Sandbox Code Playgroud)
当我执行代码时,我收到一条错误消息,
AttributeError:“WebDriver”对象没有属性“find_element_by_xpath”
Mic*_*ntz 158
Selenium 刚刚在 version 中删除了该方法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
Run Code Online (Sandbox Code Playgroud)
您现在需要使用:
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
Run Code Online (Sandbox Code Playgroud)
在您的示例中,您将使用:
driver.find_element("xpath", '//*[@id="mG61Hd"]/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[1]/div/div[1]/input')
Run Code Online (Sandbox Code Playgroud)
为了提高可靠性,您应该考虑WebDriverWait
与 结合使用element_to_be_clickable
。
Uri*_*Uri 27
您现在可以使用:
from selenium.webdriver.common.by import By
driver.find_element(by=By.XPATH, value='//<your xpath>')
Run Code Online (Sandbox Code Playgroud)
Deb*_*anB 19
Selenium 4.3.0
* Deprecated find_element_by_* and find_elements_by_* are now removed (#10712)
Run Code Online (Sandbox Code Playgroud)
根据合并, 16 个替换字符串如下:
.find_element_by_class_name(
.find_element(By.CLASS_NAME,
.find_element_by_css_selector(
.find_element(By.CSS_SELECTOR,
.find_element_by_id(
.find_element(By.ID,
.find_element_by_link_text(
.find_element(By.LINK_TEXT,
.find_element_by_name(
.find_element(By.NAME,
.find_element_by_partial_link_text(
.find_element(By.PARTIAL_LINK_TEXT,
.find_element_by_tag_name(
.find_element(By.TAG_NAME,
.find_element_by_xpath(
.find_element(By.XPATH,
.find_elements_by_class_name(
.find_elements(By.CLASS_NAME,
.find_elements_by_css_selector(
.find_elements(By.CSS_SELECTOR,
.find_elements_by_id(
.find_elements(By.ID,
.find_elements_by_link_text(
.find_elements(By.LINK_TEXT,
.find_elements_by_name(
.find_elements(By.NAME,
.find_elements_by_partial_link_text(
.find_elements(By.PARTIAL_LINK_TEXT,
.find_elements_by_tag_name(
.find_elements(By.TAG_NAME,
.find_elements_by_xpath(
.find_elements(By.XPATH,
Run Code Online (Sandbox Code Playgroud)
因此,您必须有效地替换以下代码行:
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')
Run Code Online (Sandbox Code Playgroud)
作为:
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')
Run Code Online (Sandbox Code Playgroud)
您还需要By
按如下方式导入:
from selenium.webdriver.common.by import By
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
183957 次 |
最近记录: |