我正在 Python 中使用 Selenium 创建自动化,但是当我运行此代码时,它仅正确执行第一个函数,即 select_filter_options('Seniority', selected_seniority) ,而脚本忽略它旁边的其他函数。您认为我的代码有什么问题?谢谢!!!
def select_filter_options(filter_name, selected_options):
# Find and click the filter button
filter_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, f"//div[text()='{filter_name}']/ancestor::a")))
filter_button.click()
# Find and click the span element to open the dropdown
span = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='rs-input-group-addon']")))
span.click()
# Loop through each selected option
for option in selected_options:
# Find and click the item label for the option
item_label_xpath = f"//div[@class='SearchFilterFieldInput__ItemLabel-giZgoQ ifCFA' and text()='{option}']"
item_label = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, item_label_xpath)))
item_label.click()
# Select seniority options
select_filter_options('Seniority', selected_seniority)
# Select department options
select_filter_options('Department', selected_departments)
# Select employee size options
select_filter_options('Employee Size', selected_sizes)
# Select revenue options
select_filter_options('Revenue', selected_revenue)
过滤器上的所有功能都可以正确执行
当你说被忽视时,结果是什么?您的测试是否通过并且在运行时没有抛出异常/错误?你尝试过调试你的代码吗?这些信息可能有助于提出可行的解决方案。