Selenium WebDriver on IE 9, on clicking, links are flashing as if some click event was not completely handled

点点圈 提交于 2019-12-10 12:24:37

问题


This question is regarding Selenium WebDriver running on Internet Explorer.

On Internet Explorer, the vary basic selenium method that is click() does not works most the of the time. This is my code:

System.setProperty("webdriver.ie.driver", "<path_to_iedriverserver>");
DesiredCapabilities d = DesiredCapabilities.internetExplorer();
//d.setCapability("nativeEvents", false);
webdriver = new InternetExplorerDriver(d);
webdriver.get("http://google.co.uk");
webdriver.findElement(By.linkText("Images")).click();
webdriver.findElement(By.linkText("Search")).click();

This script usually clicks "Images" link successfully, but in some cases it fails to click "Search" afterwards. It is not a synchronization issue, the same issue happens when there is a, say, Thread. Sleep() between the clicks. Moreover, if script is stopped at the breakpoint after this code and user tries to click links manually, it does not work either, but URL's keep flashing in the Internet Explorer status bar as if some click event was not completely handled. When IEDriverServer.exe process is killed, this browser window becomes responsive again.

This is my system information:

Selenium version: 4.42.2
OS: Windows 7
Browser: IE 9, IEDriverServer_Win32_2.42.0,

回答1:


In IE, most of the times click() does not work. I have faced this several times and I take different approach which works in all browsers.

Use sendKeys(Enter) instead of click() and that should work.

webdriver.findElement(By.linkText("Images")).sendKeys(KEYS.ENTER));



回答2:


You can also consider invoking java script click on the element.

WebElement element = driver.findElement(By.id("value"));
JavascriptExecutor jse= (JavascriptExecutor)driver;
jse.executeScript("arguments[0].click();", element);


来源:https://stackoverflow.com/questions/24958314/selenium-webdriver-on-ie-9-on-clicking-links-are-flashing-as-if-some-click-eve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!