Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python中使用Selenium在第一个下拉列表的基础上等待第二个下拉列表加载_Python_Selenium_Selenium Webdriver_Xpath_Wait - Fatal编程技术网

如何在Python中使用Selenium在第一个下拉列表的基础上等待第二个下拉列表加载

如何在Python中使用Selenium在第一个下拉列表的基础上等待第二个下拉列表加载,python,selenium,selenium-webdriver,xpath,wait,Python,Selenium,Selenium Webdriver,Xpath,Wait,我正在尝试使用selenium测试表单。通过下面的代码,我可以从第一个下拉菜单中选择一个项目,但在从第二个下拉菜单中选择之前它崩溃了 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=",")

我正在尝试使用selenium测试表单。通过下面的代码,我可以从第一个下拉菜单中选择一个项目,但在从第二个下拉菜单中选择之前它崩溃了

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()
无法找到第二个下拉列表的下拉列表元素。有人能帮忙排除故障吗?(代码中的最后一行在我的代码中正确缩进)

您可以尝试在两个下拉列表之间添加wait(最好是fluent)