选择下拉框不会激活Edge Selenium WebDriver的Edge浏览器上的确认对话框窗口

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

我在使用Microsoft Edge上的下拉框时遇到问题。 Chrome,Firefox或IE(v9-11)上不会出现此问题。

我在其代码中为其他Web浏览器选择下拉框的命令是Select命令:

选择(driver.find_element_by_id( “active_config”))。select_by_visible_text(CONFIGFILE)

选择配置文件后,会出现一个对话框,要求用户确认更改。但是,在Edge上,所选配置文件显示在下拉框中,但由于某种原因,确认配置文件更改的对话框永远不会弹出,因此测试失败。

当我手动测试场景[使用我的鼠标]时,它工作正常。我还使用了一个睡眠计时器[在我的测试]和鼠标确认Edge由Selenium提出时没有问题因为我在极少数情况下发生了这种情况。这几乎就像选择文件时一样,它的选择方式不会导致执行确认对话框操作。我已经尝试了下面的各种方法,但似乎没有什么可以做到的。

driver.find_element_by_xpath("//select[@id='active_config']/option[text()='" + configFile + "']").double_click()

<>

menu = driver.find_element_by_id("active_config")
submenu = driver.find_element_by_xpath("//select[@id='active_config']/option[text()='" + configFile + "']")
ActionChains(driver).move_to_element(menu).click(submenu).perform()

<>

Select(driver.find_element_by_id("active_config")).select_by_visible_text(configFile)
driver.find_element_by_id("active_config").send_keys(Keys.ENTER)

<>

driver.find_element_by_xpath("//select[@id='active_config']/option").click()
Select(self.driver.find_element_by_id("active_config")).select_by_visible_text(configFile)

<>

Select(driver.find_element_by_id("active_config")).select_by_visible_text(configFile)
Select(driver.find_element_by_id("active_config")).select_by_visible_text(configFile)

<>

Select(driver.find_element_by_id("active_config")).select_by_visible_text(configFile)
driver.find_element_by_id("active_config").send_keys(Keys.NULL)

<>

  success = False
     tries = 0
     while success == False:
         try:
             Select(driver.find_element_by_id("active_config")).select_by_visible_text(configFile)
             assertExpectedConditionTrue(self.driver, "By.LINK_TEXT", "Activate "+ configFile)
             success == True
         except NoSuchElementException:
             tries = tries + 1
             if tries == 3:
                 raise Exception ("EDGE WON'T SELECT NEW PROFILE")
             else:
                 time.sleep(1)

<>

driver.find_element_by_xpath("//select[@id='active_config']/option[text()='" + configFile + "']").click()

<>

Select(driver.find_element_by_xpath("//select[@id='active_config']")).select_by_visible_text(configFile)

在这一点上,我很难过,不知道该尝试什么。建议?

python selenium selenium-webdriver webdriver microsoft-edge
1个回答
0
投票

解决方案是使用Action Chains。

.move_to_element()。click()和Select()不适用于Edge。在Chrome,Firefox和IE上,我可以指向下拉列表的位置,并返回一个配置文件列表。

driver.find_element_by_id("active_config")

- 要么 -

driver.find_element_by_xpath("//select[@id='active_config']")

Edge上的情况并非如此。当我指向Edge上的相同位置时,它将不返回任何内容。我怀疑这就是“充电”事件永远不会发生的原因,即使使用Select()会在框中显示我想激活的配置文件。我在Edge上的其他下拉列表中遇到了同样的问题。奇怪的是,如果我单独指向列表中的每个项目,我可以让Selenium返回其值。

driver.find_element_by_xpath("//select[@id='active_config']/option[1]")
driver.find_element_by_xpath("//select[@id='active_config']/option[2]")
driver.find_element_by_xpath("//select[@id='active_config']/option[3]")
ect...

因此,我必须执行以下操作才能解决我的问题:

  1. 创建一个包含所有配置文件的列表。 active_config_list = [] num_of_active_configs = 0 new_config_loc = None curr_config_loc = None try: while True: active_config_list.append(self.driver.find_element_by_xpath("//select[@id='active_config']/option[" + str(num_of_active_configs + 1) + "]").text) num_of_active_configs = num_of_active_configs + 1 except NoSuchElementException: pass
  2. 存储活动配置文件和我要激活的配置文件的位置。这样,我知道需要按下“向上箭头”或“向下箭头”键以突出显示我想要的配置文件的次数。 for cnt in xrange(0, num_of_active_configs): if self.ncdFile == active_config_list[cnt]: new_config_loc = cnt + 1 if not re.search (r"No .ncd file is active.", self.driver.find_element_by_id("active_conf").text) == None: curr_config_loc = 1 break else: active_config_string = self.driver.find_element_by_id("active_conf").text.split() for cnt in xrange(0, num_of_active_configs): if str(active_config_string[0]) == active_config_list[cnt]: curr_config_loc = cnt + 1 break break
  3. 使用Action Chains激活列表,使用箭头键选择所需的配置文件,然后按Enter键。 menu = self.driver.find_element_by_id("active_config") ActionChains(self.driver).move_to_element(menu).click(menu).perform() if curr_config_loc < new_config_loc: for x in xrange(0, new_config_loc - curr_config_loc): ActionChains(self.driver).key_down(Keys.ARROW_DOWN).perform() elif curr_config_loc > new_config_loc: for x in xrange(0, curr_config_loc - new_config_loc): ActionChains(self.driver).key_down(Keys.ARROW_UP).perform() ActionChains(self.driver).key_down(Keys.ENTER).perform()
© www.soinside.com 2019 - 2024. All rights reserved.