Python Selenium使用select方法时出现'module' object is not callable错误
问题解决
错误原因
- 你误将Selenium的
Select类所在的模块当作可调用对象使用——select是模块名,不是可实例化的类,正确的类是selenium.webdriver.support.ui下的Select。 - 代码存在拼写错误:
selectByVisbleText应为select_by_visible_text(Python版本的Selenium方法采用蛇形命名,且单词"Visible"拼写错误)
修正后的代码
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select # 导入正确的Select类 dob = 12 driver = webdriver.Chrome() driver.get("https://www.avant.com/apply") driver.implicitly_wait(10) # 实例化Select类,注意首字母大写 month = Select(driver.find_element(By.ID, 'person_date_of_birth_month')) if dob == 12: # 使用正确的方法名 month.select_by_visible_text('Jan')
内容的提问来源于stack exchange,提问作者thrvxx
相关产品推荐
相关产品推荐

