无法从下拉列表中选择所需的值,它始终选择第一个值(Python、Selenium)

Unable to select the desirable value from a dropdown list, it always selects the 1st one (Python, Selenium)

提问人:sugarakis 提问时间:11/17/2023 更新时间:11/17/2023 访问量:24

问:

我正在尝试使用 Python 和 Selenium 将用户分配给特定的 Mantis Bug。我的代码(如下)在执行时总是选择第一条记录(Alfred Kan),而不是我在代码中手动选择的记录(Bryan Lu)。我的代码如下:

    driver.get("https://mantis-dev.{company}.com/bug_view_page.php?bug_id=0794544")
    form = driver.find_element(By.XPATH, '//form[@action="bug_assign.php"]')
    dropdown = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.CSS_SELECTOR, '.chosen-single'))
    )
    dropdown.click()
    
    driver.execute_script("arguments[0].click();", WebDriverWait(driver, 10).until
        (EC.element_to_be_clickable((By.XPATH, '//li[text()="Bryan Lu (bryanlu)"]'))))
    assign_button = driver.find_element(By.XPATH, '//input[@type="submit" and @value="Assign To:"]')
    assign_button.click()
    driver.quit()

这是 Mantis Bug 页面中显示下拉列表的部分

enter image description here

这是代码隐藏

enter image description here

我将不胜感激任何帮助,谢谢

python selenium-webdriver 螳螂

评论


答: 暂无答案