Venkatesh Venkatesh - 5 months ago 50
Java Question

Selenium Webdriver IE could not find element

I am trying to navigate to

www.google.com
and send some inputs to search box using Selenium webdriver with Internet Explorer(IE).

static WebDriver webDriver = null;
static DesiredCapabilities IEDesiredCapabilities = DesiredCapabilities.internetExplorer();

System.setProperty("webdriver.chrome.driver", TestConstants.chromeDriverFilePath);
System.setProperty("webdriver.ie.driver", TestConstants.IEDriverFilePth);

IEDesiredCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
webDriver = new InternetExplorerDriver(IEDesiredCapabilities);
//webDriver = new ChromeDriver();

webDriver.navigate().to("http://www.google.com");
webDriver.findElement(By.name("q")).sendKeys("Venkatesh Kolisetty");
//webDriver.findElement(By.id("lst-ib")).sendKeys("Venkatesh Kolisetty");


This piece of code runs very well when i use Chrome, but throws
org.openqa.selenium.NoSuchElementException
when IE is used.


This opens required web page in the IE browser which is opened by selenium. The problem is selenium is not able to find any element after page is loaded only when IE is used. For chrome, it finds required elements.


Is there any capability to be added in
IEDesiredCapabilities


Kindly see the possibility of providing a programmatic solution instead of changing internet options manually.

Answer

Issue resolved after adding some required capabilities.

IEDesiredCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
IEDesiredCapabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "http://www.google.com");
IEDesiredCapabilities.internetExplorer().setCapability("ignoreProtectedModeSettings", true);
IEDesiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
IEDesiredCapabilities.setJavascriptEnabled(true);
//IEDesiredCapabilities.setCapability("requireWindowFocus", true);
IEDesiredCapabilities.setCapability("enablePersistentHover", false);

IEDesiredCapabilities.setCapability("requireWindowFocus", true); is optional