selenium 尝试从下拉菜单中选择内容时,出现“TypeError:‘WebDriver’Object is Not Callable”(类型错误:无法调用‘WebDriver’对象

ryevplcw  于 2022-11-10  发布在  其他
关注(0)|答案(1)|浏览(558)

尝试执行以下操作时出现以下错误:

Traceback (most recent call last):
  File "c:\Users\seal\doc\main\main.py", line 172, in <module>
    select()
  File "c:\Users\seal\doc\main\main.py", line 108, in select
    drop = driver(By.ID, 'fulfillment_duration')
TypeError: 'WebDriver' object is not callable

driver = webdriver.Chrome()
drop = driver(By.ID, 'fulfillment_duration') 
drop.select_by_value("one_day")

我将如何修复此问题,以及如何从下拉列表中选择内容?
以下是元素:

<select aria-invalid="false" id="fulfillment_duration" name="fulfillment_duration" class="Select-element PressableContext Padding-right--24 Padding-left--8 Padding-vertical--4 PressableContext--cursor--pointer PressableContext--display--inlineFlex PressableContext--fontLineHeight--20 PressableContext--fontSize--14 PressableContext--fontWeight--medium PressableContext--height PressableContext--height--medium PressableContext--radius--all PressableContext--width PressableContext--width--auto" style="color: rgb(64, 68, 82);"><option disabled="" value="">Please select…</option><option value="one_day">Within one day</option><option value="two_weeks">Within 2 weeks</option><option value="one_month">Within one month</option><option value="months">More than one month</option></select>

我想选择“One_day”选项。
提前谢谢!

1l5u6lss

1l5u6lss1#

而不是drop = driver(By.ID, 'fulfillment_duration')
尝试

drop = driver.find_element(By.ID, 'fulfillment_duration')

此外,您可能需要在此处引入延迟,因此更好的代码是:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 20)

drop = wait.until(EC.presence_of_element_located((By.ID, 'fulfillment_duration')))

相关问题