如何基于Python中使用Selenium的第一个下拉菜单等待第二个下拉列表加载

问题描述 投票:1回答:1

使用硒,我正在尝试测试this page上的表格。通过下面的代码,我可以从第一个下拉菜单中选择一个项目,但是它在崩溃之前无法从第二个下拉菜单中进行选择。

def test_apply_forms(self):
        FILE_PATH = "tests/forms/apply.csv"
        with open(FILE_PATH) as csv_file:
            csv_reader = csv.reader(csv_file, delimiter=",")
            headers = next(csv_reader)
            for row in csv_reader:
                form = dict(zip(headers, row))

                # Your Internship
                dropdown_xpath = "//span[@id='select2-chosen-2']"
                self.driver.find_element_by_xpath(dropdown_xpath).click()
                choice_xpath = f"//div[contains(text(),'{form[headers[0]]}')]"
                self.driver.find_element_by_xpath(choice_xpath).click()

                # Your Session
                dropdown_xpath = "//span[contains(text(),'Choose a session')]"
                self.driver.find_element_by_xpath(dropdown_xpath).click()
                choice_xpath = f"//div[contains(text(),'{form[headers[1]]}')]"
self.driver.find_element_by_xpath(choice_xpath).click()

无法找到第二个下拉菜单的下拉菜单元素。任何人都可以帮助排除故障吗? (代码的最后一行在我的代码中已正确缩进)

selenium selenium-webdriver xpath wait
1个回答
0
投票

您可以尝试在两个下拉菜单之间添加等待(最好流利)。

© www.soinside.com 2019 - 2024. All rights reserved.