Java Selenium悬停代码适用于Chrome而非Edge
这是工作在铬。不是边缘。我已经向开发人员确认,我正在正确的元素上“悬停”Java Selenium悬停代码适用于Chrome而非Edge,java,selenium,selenium-webdriver,webdriver,action,Java,Selenium,Selenium Webdriver,Webdriver,Action,这是工作在铬。不是边缘。我已经向开发人员确认,我正在正确的元素上“悬停” public void Hover() { Actions action = new Actions(BrowserWindow.Instance.Driver); action.MoveToElement(WebElement).Perform(); } 这也不起作用。有人知道我做错了什么吗 更多信息。 这在Firefox上也是失败的。我看到一篇关于过时的selenium驱动程序的文章。我刚刚安装了ge
public void Hover()
{
Actions action = new Actions(BrowserWindow.Instance.Driver);
action.MoveToElement(WebElement).Perform();
}
这也不起作用。有人知道我做错了什么吗
更多信息。
这在Firefox上也是失败的。我看到一篇关于过时的selenium驱动程序的文章。我刚刚安装了geckodriver,并根据文档将Edge驱动程序设置为自动更新。我不相信我有过时的司机
更多信息获取2
呼叫代码是
WebElement elem = yourWebDriverInstance.findElement(By.xpath("//*[@class='goog-menu goog-menu-vertical uploadmenu density-tiny']/input"));
String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
((JavascriptExecutor) yourWebDriverInstance).executeScript(js, elem);
如果我在按钮关闭时设置断点。。。尝试悬停后,我注意到将鼠标移到“选项卡”上也不会导致按钮可见 这太奇怪了。但是替换
public static void DoCloseActiveTabEntire()
{
Element tab = new Element(byTab);
tab.Hover();
// CLose button is not clickable. Cannot use standard BUTTON for find
Button close = new Button(byClosePanelButton);
close.Click();
}
与
它是有效的。我读到构建是内置在Perform中的。但我只是想拍一下,希望有什么东西掉出来。它成功了。perform()
是在不首先调用build()
的情况下执行操作的方便方法
build()
生成一个复合操作,其中包含到目前为止准备执行的所有操作,此外还重置内部生成器状态,因此对build()
的后续调用将包含新序列
这个用例 在您的用例中,您已经在
moveToElement(WebElement)
之后调用了perform()
,而没有生成要使用build()
执行的复合操作
解决方案 一个简单的解决方案是在
perform()
之前调用build()
,如下所示:
action.MoveToElement(WebElement).Build().Perform();
所以,我不知道为什么我认为build().perform()完成了这项工作。我知道它曾经奏效过。我最后要做的是保持悬停代码不变
public void Hover()
{
Actions action = new Actions(BrowserWindow.Instance.Driver);
action.moveToElement(WebElement).build().perform();
}
我更改了调用代码,该代码尝试关闭面板/页面,无论我想调用什么:
public void Hover()
{
Actions action = new Actions(BrowserWindow.Instance.Driver);
action.MoveToElement(WebElement).Build().Perform();
Thread.Sleep(1000);
}
对我来说,我很高兴事情可以结束。我不太在乎悬停是否达到了目的 看起来,就像它的已知问题一样,可能还没有解决。令人困惑的是,你链接到的评论说“应该在版本10586中得到支持”,而这个驱动程序已经有很多版本超过了这个版本。是的,我看到了。当我试图打开一些特殊链接时,EDGE也出现了问题,但它崩溃了。这是我在Microsoft网站上发现的已知问题报告错误,它说,该问题在EDGE 15中已修复,但即使在版本18中也未修复,所以idk。您是否尝试将鼠标悬停在嵌套元素或父元素上?“onhover”事件可能在另一个元素上处理。我很困惑。它成功了。不,它不再工作了。再次强调,仅限边缘。“hover”代码执行时不会出错。但是这个应该被显示的按钮并没有导致它的点击出错。希望能更新你们所有有用的窥视。但是,尽管它进行了一些尝试,但现在却失败了。悬停代码执行时不会出错。但是,应该被显示的按钮并没有导致其点击失败。仅限边缘。
public void Hover()
{
Actions action = new Actions(BrowserWindow.Instance.Driver);
action.MoveToElement(WebElement).Build().Perform();
Thread.Sleep(1000);
}
public static void DoCloseActiveTabEntire()
{
// So there is a defect in EDGE whereby the behavior of the code containted in the hover on the tab executes without
// error but the action underneath does not occur. So in Edge, callng the hover method of the TAB as seen in the else condition
// below does nto display the CLOSE button which needs to be clicked.
// So for Edge, javascript is used to display the button directly.
IWebElement close;
if (BrowserWindow.Instance.Browser == BrowserWindow.Browsers.Edge)
{
close = BrowserWindow.Instance.Driver.FindElement(byClosePanelButton);
string js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible'; arguments[0].style.display='inline';";
IWebDriver driver = BrowserWindow.Instance.Driver;
IWebElement element = close;
((IJavaScriptExecutor)driver).ExecuteScript(js, element);
}
else
{
Element tab = new Element(byTab);
tab.Hover();
close = new Button(byClosePanelButton).WebElement;
}
close.Click();
}