Edge 浏览器未在 Selenium 测试中接收下拉更改事件
Edge browser is not receving dropdown change event in Selenium test
我正在努力使用 Edge WebDriver 自动下拉菜单
驱动版本 10.0.1586.0
public void selectFromDropdown(By dropdownLocator, String optionToChoose) {
Select select = new Select(getElementWhenPresent(dropdownLocator));
select.selectByVisibleText(optionToChoose);
}
不支持 Edge WebDriver,但支持 IE8-11、Chrome、FF。实际上下拉菜单在测试期间更改了它的值 运行,但 Edge 浏览器忽略了这一点。 Browser/driver 错误?
编辑
使用 jQuery 设置下拉值也不会触发更改事件
public void selectFromDropdown(By dropdownLocator, String optionToChoose) {
if(this.getName() == BrowserName.EDGE || this.getName() == BrowserName.EDGE_GRID){
// Select option with jQuery
JavascriptExecutor executor = (JavascriptExecutor) driver;
initializeJQuery();
String $dropdown = "#" + getElementWhenPresent(dropdownLocator).getAttribute("id");
executor.executeScript("$(\"" + $dropdown + "\").val($(\"" + $dropdown + " > option\").filter(function () { return $(this).html() == \"TPI\"; }).val())");
} else {
Select select = new Select(getElementWhenPresent(dropdownLocator));
select.selectByVisibleText(optionToChoose);
}
}
jQuery 执行的代码:
$("#selectId").val($("#selectId> option").filter(function () { return $(this).html() == "OPTION TEXT"; }).val())
编辑
HTML 的下拉元素(这里没什么特别的):
<select class="form-control" id="operations">
<option value="-1_*">Name 1</option>
<option value="9_*">Name 2</option>
<option value="16_B7">Name 3</option>
</select>
最后 使用 sendKeys() 解决了它,所以我正在检查是否在 Edge 上执行测试并使用 sendKeys() 方法设置 <select>
选项:
public void selectFromDropdown(By dropdownLocator, String optionToChoose) {
if(this.getName() == BrowserName.EDGE){
getElementWhenPresent(dropdownLocator).sendKeys(optionToChoose);
} else {
Select select = new Select(getElementWhenPresent(dropdownLocator));
select.selectByVisibleText(optionToChoose);
}
}
我正在努力使用 Edge WebDriver 自动下拉菜单
驱动版本 10.0.1586.0
public void selectFromDropdown(By dropdownLocator, String optionToChoose) {
Select select = new Select(getElementWhenPresent(dropdownLocator));
select.selectByVisibleText(optionToChoose);
}
不支持 Edge WebDriver,但支持 IE8-11、Chrome、FF。实际上下拉菜单在测试期间更改了它的值 运行,但 Edge 浏览器忽略了这一点。 Browser/driver 错误?
编辑
使用 jQuery 设置下拉值也不会触发更改事件
public void selectFromDropdown(By dropdownLocator, String optionToChoose) {
if(this.getName() == BrowserName.EDGE || this.getName() == BrowserName.EDGE_GRID){
// Select option with jQuery
JavascriptExecutor executor = (JavascriptExecutor) driver;
initializeJQuery();
String $dropdown = "#" + getElementWhenPresent(dropdownLocator).getAttribute("id");
executor.executeScript("$(\"" + $dropdown + "\").val($(\"" + $dropdown + " > option\").filter(function () { return $(this).html() == \"TPI\"; }).val())");
} else {
Select select = new Select(getElementWhenPresent(dropdownLocator));
select.selectByVisibleText(optionToChoose);
}
}
jQuery 执行的代码:
$("#selectId").val($("#selectId> option").filter(function () { return $(this).html() == "OPTION TEXT"; }).val())
编辑
HTML 的下拉元素(这里没什么特别的):
<select class="form-control" id="operations">
<option value="-1_*">Name 1</option>
<option value="9_*">Name 2</option>
<option value="16_B7">Name 3</option>
</select>
最后 使用 sendKeys() 解决了它,所以我正在检查是否在 Edge 上执行测试并使用 sendKeys() 方法设置 <select>
选项:
public void selectFromDropdown(By dropdownLocator, String optionToChoose) {
if(this.getName() == BrowserName.EDGE){
getElementWhenPresent(dropdownLocator).sendKeys(optionToChoose);
} else {
Select select = new Select(getElementWhenPresent(dropdownLocator));
select.selectByVisibleText(optionToChoose);
}
}