Selenium从下拉列表中选择值不能在Edge/Safari中工作,但在其他浏览器中可用

Selenium从下拉列表中选择值不能在Edge/Safari中工作,但在其他浏览器中可用

问题描述:

我有一个页面,其中有一个下拉列表,您可以在不同选项之间切换,并加载一个新页面,我试图自动执行测试。但是,在Safari/Edge上,选择功能永远不会更改该选项。我曾尝试使用.click方法以及执行脚本以将元素上的属性更改为“selected”。在Chrome/FF/IE中,这一切都正常。我将这个函数封装在try catch中,并且没有任何错误出现,它只是没有做任何事情。我在这里做错了什么?Selenium从下拉列表中选择值不能在Edge/Safari中工作,但在其他浏览器中可用

from selenium.webdriver.common.by import By 
from selenium.webdriver.support.ui import WebDriverWait, Select 
from selenium.webdriver.support import expected_conditions as EC 

def test_safari_edge(self): 
    try: 
     WebDriverWait(self.driver, 10).until(
      EC.presence_of_element_located(self.tp.org_dropdown_options) 
     ) 
     select = Select(self.tp.find_element_by(By.CSS_SELECTOR, 'div.js-org-switcher.org-name-wrapper > select')) 
     select.select_by_value('myorg') 
    except Exception as e: 
     print(e) 

我运行在不同的操作系统测试和每一个测试不同的浏览器,但只有我发现使用Safari的webdriver这个问题。

当前版本硒:3.6

搜索,并试图像更新的MacOS的WebKit的或使用选择一些提示()后,在几个方面,我决定使用JavaScript。

@when(u'I set the example dropdown to "{option}"') 
def step_impl(context, option): 
    selenium = context.selenium 

    selenium.execute_script(u"""                        
     $("select[name='dropdown']").val('{0}');                  
    """.format(option)); 

适用于所有等待WebDriver解决方案的浏览器。