我正在尝试使用 c# Selenium WebDriver 中的 Actions 类双击选择框中的选项。以下代码适用于 firefox,但不适用于 IE 或 Chrome。关于为什么或如何调查问题的任何建议?
var sideBarAgentList = new SelectElement(driver.FindElement(By.CssSelector("#agentSelectBox")));
var agentInList = sideBarAgentList.Options.First(o => o.Text == "Agent49159 - 49159");
new Actions(driver).DoubleClick(agentInList).Perform();
HTML 是
<select id="agentSelectBox" ondblclick="javascript:addAgentDesktop(this.selectedIndex);" onchange="javascript:showAgentInfo(this.selectedIndex);" style="width:220px;background:#e0e0e0;font-family:Verdana;font-size:75%;" size="22">
<option value="0" style="background:white;color:blue">
Agent49159 - 49159
</option>
</select>
最佳答案
据我所知,双击操作在 IE 或 Chrome 中对选择元素中的选项不起作用。我更新了我的代码以单击选择菜单中的选项,然后双击选择元素本身而不是选项。适用于 FF、IE 和 Chrome。
new SelectElement(driver.FindElement(By.CssSelector("#agentSelectBox"))).Options.First(o => o.Text == "Agent49159 - 49159").Click();;
new Actions(driver).DoubleClick(driver.FindElement(By.CssSelector("#agentSelectBox"))).Perform();
关于c# - 无法在 selenium webdriver c# 中双击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26279368/