硒哈弗元素与IE浏览器元素、浏览器、哈弗、IE

2023-09-03 17:39:38 作者:呆子丶speak

我有一个HTML DIV 标记和DIV中有,当鼠标进入其边界出现在一个元素。现在,我想点击变成鼠标进入或悬停可见元素。

I have an HTML div tag and inside the div there is an element which appears in when mouse enters its boundaries. Now I want to click on the element which becomes visible on mouse entering or hovering.

问题:元素开始闪烁。 浏览器:IE8

Issue: the element starts blinking. Browser: IE8

我使用以下

   IWebElement we = addToBasket.FindElement(By.Id("MyBox"));
   action.MoveToElement(we).MoveToElement(driver.FindElement(By.Id("plus-icon"))).Click().Build().Perform();

任何建议,为什么它闪烁?

Any suggestion why its blinking?

推荐答案

元素闪烁因为IE司机叫的一个特点持续徘徊。此功能的可疑值,但由于脑死亡途径的IE(浏览器,而不是驱动)响应 WM_MOUSEMOVE 邮件使用 SendMessage函数 API时的。

The element is blinking because of a feature of the IE driver called "persistent hovers." This feature is of dubious value, but is required because of the brain-dead way IE (the browser, not the driver) responds to WM_MOUSEMOVE messages when using the SendMessage API.

您有几种选择。您可以通过使用code像下面这样把持续徘徊关闭:

You have a few options. You can turn persistent hovers off by using code like the following:

InternetExplorerOptions options = new InternetExplorerOptions();
options.EnablePersistentHover = false;
IWebDriver driver = new InternetExplorerDriver(options);

但请注意,这将受到您所在的物理鼠标光标在屏幕上,当你尝试悬停率性。如果这是不能接受的,你有一个几个其他的方法你可以采取。首先,你可以关闭所谓的原生的事件,这将导致驱动程序仅仅依靠合成JavaScript事件。这种方法有其自身的缺陷,由于只依靠JavaScript来合成鼠标事件。

Be aware, though that this will subject you to the whims of where the physical mouse cursor is on the screen when you attempt to hover. If that's not acceptable, you have a couple of other approaches you could take. First, you could turn off so-called "native events," which would cause the driver to rely solely on synthesized JavaScript events. This approach has its own pitfalls, due to relying only on JavaScript to synthesize the mouse events.

InternetExplorerOptions options = new InternetExplorerOptions();
options.EnableNativeEvents = false;
IWebDriver driver = new InternetExplorerDriver(options);

最后,你可以迁移使用默认的 SendMessage函数 Windows API的code,它使用了更正确的 SendInput API。这样做是与 RequireWindowFocus 属性。其缺点是,鼠标输入在系统中的一个非常低的水平,这需要IE窗口是系统上的前景窗口注射

Finally, you could migrate from using the default SendMessage Windows API to code that uses the more correct SendInput API. This is done with the RequireWindowFocus property. Its drawback is that the mouse input is injected at a very low level in the system, which requires the IE window to be the foreground window on the system.

InternetExplorerOptions options = new InternetExplorerOptions();
options.RequireWindowFocus = true;
IWebDriver driver = new InternetExplorerDriver(options);

最后要注意,不要试图将所有这些属性的一次;挑选的方法,并坚持下去。其中几个是相互排斥的,并且它们之间的相互作用是不确定的。

As a final note, do not attempt to set all of these properties at once; pick an approach and stick with it. Several of them are mutually exclusive, and the interaction between them is undefined.