由於IE驅動程序稱爲「永久懸停」的功能,元素閃爍。此功能具有可疑價值,但因使用SendMessage
API而導致的腦死亡方式IE(瀏覽器,而不是驅動程序)responds to WM_MOUSEMOVE
messages,因此是必需的。
您有幾個選項。您可以通過使用類似於下面的代碼把持久徘徊關閉:
InternetExplorerOptions options = new InternetExplorerOptions();
options.EnablePersistentHover = false;
IWebDriver driver = new InternetExplorerDriver(options);
但請注意,這將導致您遭受的其中物理鼠標光標在屏幕上,當你嘗試懸停率性。如果這是不可接受的,你有一個couple of other approaches你可以採取。首先,您可以關閉所謂的「本地事件」,這會導致驅動程序完全依賴合成的JavaScript事件。由於僅依靠JavaScript來合成鼠標事件,因此此方法有其自身的缺陷。
InternetExplorerOptions options = new InternetExplorerOptions();
options.EnableNativeEvents = false;
IWebDriver driver = new InternetExplorerDriver(options);
最後,你可以使用默認的SendMessage
用Windows API代碼,使用更正確的SendInput
API遷移。這是通過RequireWindowFocus
屬性完成的。它的缺點是鼠標輸入在系統中被注入很低的級別,這要求IE窗口成爲系統的前景窗口。
InternetExplorerOptions options = new InternetExplorerOptions();
options.RequireWindowFocus = true;
IWebDriver driver = new InternetExplorerDriver(options);
作爲最後一點,不要試圖一次設置所有這些屬性;選擇一種方法並堅持下去。其中有幾個是互斥的,它們之間的交互是不確定的。
您正在使用哪種版本的硒? – Karthikeyan
IE11仍然存在這個問題。幸運的是,下面的解決方案仍然有效:)。 –