gpt4 book ai didi

java - WebDriver,如何防止 InternetExplorerDriver 控制鼠标指针

转载 作者:行者123 更新时间:2023-12-01 23:08:50 25 4
gpt4 key购买 nike

每当我在 IE 中运行 WebDriver 测试(使用 InternetExplorerDriver)时,需要单击网页元素,InternetExplorerDriver 就会接管我的鼠标。

当我在 Chrome 或 Firefox 中运行测试时,不会发生这种情况。有没有办法阻止 IE 测试控制鼠标指针?

导致鼠标指针被“窃取”的示例代码:

public void clickButtonNamed(String buttonName) {
driver.findElement(By.xpath("//div[contains(text(),'" + buttonName + "')]")).click();
}

public void dragAndDropElement(WebElement source, WebElement target) throws InterruptedException {
action.dragAndDrop(source,target).build().perform();
}

//IE Driver initialization
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS,true);
WebDriver driver = new InternetExplorerDriver(caps);

最佳答案

您将此属性 InternetExplorerDriver.REQUIRE_WINDOW_FOCUS 设置为 true 是否有原因?这就是 IEDriver 要求 IE 控制您的指针的原因。

要修复它,只需将其删除或将其设置为 false 即可。这是在 2.28.0.3 中引入的,以下是来自 CHANGELOG 的引用:

Introduced the "requireWindowFocus" capability into the IE driver. When used in conjunction with the "nativeEvents" capability, thedriver will attempt to bring the current IE window to theforeground before executing a mouse or keyboard event.

Also, whenthe requireWindowFocus capability is set to true, advanced userinteractions will now use the Windows SendInput() API to executethe interactions. To enable this behavior, set the value of the
requiresWindowFocus capability to "true" when creating an instance ofthe IE driver. The default for this new capability is "false". Thisfunctionality is currently considered extremely experimental; useat your own risk.

关于java - WebDriver,如何防止 InternetExplorerDriver 控制鼠标指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22338609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com