【问题标题】:"TypeError: 'str' object is not callable" passing locator within expected_conditions through Python + Selenium“TypeError:'str'对象不可调用”通过Python + Selenium在expected_conditions中传递定位器
【发布时间】:2020-04-11 11:14:13
【问题描述】:

我收到以下错误:

Traceback(最近一次调用最后一次):文件“[redacted]”,第 69 行,in wait.until(EC.element_to_be_clickable(By.ID("RptViewer_ctl09_ctl04_ctl00_ButtonLink"))) TypeError: 'str' 对象不可调用

这是我认为导致问题的代码部分:

66   browser.find_element_by_id('RptViewer_ctl09_ctl04_ctl00_ButtonLink')
67   drp = browser.find_element_by_id('RptViewer_ctl09_ctl04_ctl00_ButtonLink')
68   wait = WebDriverWait(browser, 10)
69   wait.until(EC.element_to_be_clickable(By.ID('RptViewer_ctl09_ctl04_ctl00_ButtonLink')))
70   drp.click()

我认为导致问题的原因是“ID('RptViewer_ctl09_ctl04_ctl00_ButtonLink')”部分,但我不确定这是否属实,也不知道如何解决。非常感谢任何指导。

谢谢!

【问题讨论】:

  • 该行包含三个函数调用,所以我首先将这三个拆分为不同的行,看看哪一个是问题所在。
  • 来自文档element_to_be_clickable() 采用一个看起来像tuple 的参数。试试看:wait.until(EC.element_to_be_clickable((By.ID,'RptViewer_ctl09_ctl04_ctl00_ButtonLink'))) 注意:(By.ID,'Rpt ...

标签: python selenium selenium-webdriver webdriverwait expected-condition


【解决方案1】:

By.ID 是一个字符串。不可调用。预期条件采用元组形式的定位器(正如 quamrana 已经建议的那样)

【讨论】:

    【解决方案2】:

    在将WebDriverWaitexpected_conditions 结合使用时,您必须将定位器括在一个元组中,如下所示:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "RptViewer_ctl09_ctl04_ctl00_ButtonLink")))
    

    【讨论】:

      猜你喜欢
      • 2019-08-24
      • 2020-11-06
      • 2023-01-15
      • 2022-01-08
      • 2020-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多