“TypeError:'str'object is not callable”通过Python+Selenium在预期的\u条件内传递定位器

2024-09-29 23:31:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我收到以下错误:

Traceback (most recent call last): File "[redacted]", line 69, in wait.until(EC.element_to_be_clickable(By.ID("RptViewer_ctl09_ctl04_ctl00_ButtonLink"))) TypeError: 'str' object is not callable

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

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\u ctl09\u ctl04\u ctl00\u ButtonLink')”部分,但我不确定这是不是真的,也不确定如何修复它。非常感谢您的指导。你知道吗

谢谢!你知道吗


Tags: tobrowseridbyelementbeuntilwait
2条回答

在使用WebDriverWaitexpected_conditions连接时,必须将定位器包含在元组中,如下所示:

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

你知道吗按ID是字符串。不能打电话。期望条件采用元组形式的定位器(正如quamrana已经建议的那样)

相关问题 更多 >

    热门问题