Selenium basepage 报这个错,怎么解决,AttributeError: 'tuple' object has no attribute 'send_keys'

testjson · 2022年10月09日 · 最后由 只是一个拿锤子的约德尔人 回复于 2022年10月12日 · 7101 次阅读



共收到 5 条回复 时间 点赞
6楼 已删除

tuple 是一个元组,元组怎么会有 send keys 的方法呢?元素才有吧

恒温 回复
def __find_element__(self, lc, locator):
    """元素定位"""
    if lc == "id":
        ele = self.driver.find_element(By.ID, locator)
        print(type(ele))
        WebDriverWait(self.driver, 10).until(ec.visibility_of_element_located(ele))
<class 'selenium.webdriver.remote.webelement.WebElement'>
Traceback (most recent call last):
  File "D:/demo_123/basic/page.py", line 48, in <module>
    a.__find_element__('id','kw').send_keys('python')
  File "D:/demo_123/basic/page.py", line 19, in __find_element__
    WebDriverWait(self.driver, 10).until(ec.visibility_of_element_located((ele)))
  File "D:\demo_123\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 81, in until
    value = method(self._driver)
  File "D:\demo_123\venv\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 125, in _predicate
    return _element_if_visible(driver.find_element(*locator))
TypeError: find_element() argument after * must be an iterable, not WebElement
def __find_element__(self, lc, locator):
    """元素定位"""
    if lc == "id":
        #ele = self.driver.find_element(By.ID, locator)
        ele = WebDriverWait(self.driver, 10).until(ec.visibility_of_element_located((By.ID,locator)))

    return ele

这样调整了一下,解决了

ele 前面加个 * 应该可以解决,,不然你传过去就是一个元组。

元祖没有 sendkeys 方法

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册