WebDriver的moveToElement
在Firefox和IE中不起作用。它在Chrome浏览器中运行良好。
以下是我使用的代码:
Actions builder = new Actions(driver);
builder.moveToElement(driver.findElement(By.xpath(Loader.OR.getProperty(object))))
.moveToElement(driver.findElement(By.xpath(data)))
.click();
Action selectMultiple = builder.build();
selectMultiple.perform();
同样适用于Chrome,但不适用于IE或Firefox。
答案 0 :(得分:0)
您可以使用Javascript,但不幸的是,IE和Firefox / Chrome的脚本不同:
if (_browserName == BrowserName.InternetExplorer)
{
script = "var evt = document.createEventObject();" +
"arguments[0].fireEvent('onmouseover', evt);";
}
else
{
script = "var evt = document.createEvent('MouseEvents');" +
"evt.initMouseEvent('mouseover',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" +
"arguments[0].dispatchEvent(evt);";
}
((IJavaScriptExecutor)QuestWebDriver.CurrentDriver).ExecuteScript(script, element);
对于IE,这些selenium原生方法适用于我:
Actions action = new Actions(driver);
action.MoveToElement(element).Perform();