赞
踩
上周重装系统升级了python版本从3.6升级到了3.8,发现旧的脚本不能用了,显示如下
提示:
find_element_by_* commands are deprecated. Please use find_element() instead
看了下 为啥之前的方法不能用了,如下
def find_element_by_id(self, id_) -> WebElement:
"""Finds an element by id.
:Args:
- id\_ - The id of the element to be found.
:Returns:
- WebElement - the element if it was found
:Raises:
- NoSuchElementException - if the element wasn't found
:Usage:
::
element = driver.find_element_by_id('foo')
"""
warnings.warn(
"find_element_by_* commands are deprecated. Please use find_element() instead",
DeprecationWarning,
stacklevel=2,
)
return self.find_element(by=By.ID, value=id_)
def find_element(self, by=By.ID, value=None) -> WebElement:
"""
Find an element given a By strategy and locator.
:Usage:
::
element = driver.find_element(By.ID, 'foo')
:rtype: WebElement
"""
if isinstance(by, RelativeBy):
return self.find_elements(by=by, value=value)[0]
if by == By.ID:
by = By.CSS_SELECTOR
value = '[id="%s"]' % value
elif by == By.TAG_NAME:
by = By.CSS_SELECTOR
elif by == By.CLASS_NAME:
by = By.CSS_SELECTOR
value = ".%s" % value
elif by == By.NAME:
by = By.CSS_SELECTOR
value = '[name="%s"]' % value
return self.execute(Command.FIND_ELEMENT, {
'using': by,
'value': value})['value']
遂改成
self.driver.find_element(
By.XPATH, "//*[@id="app"]/div/div[1]/div[2]/div[2]/div/form/div[1]/div/div/input").click()
self.driver.find_element(
By.XPATH, "//*[@id="app"]/div/div[1]/div[2]/div[2]/div/form/div[1]/div/div/input").clear()
self.driver.find_element(
By.XPATH, "//*[@id="app"]/div/div[1]/div[2]/div[2]/div/form/div[1]/div/div/input").send_keys("mayubo")
记得加一下from selenium.webdriver.common.by import By
解决。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。