简体   繁体   中英

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.

Yes this is common issue when you use IE.

Open regedit.exe

Open HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones

So Zones will contain 0,1,2,3,4 and on right hand side three columns will be visible as soon as you click on 0 ie Name Type Data

Now in Name column look for 2500 Double click it. Put Value data as 3 and Base as Hexadecimal

You did this for 0.

Now repeat the same steps for 1,2,3,4..

Do this for all ie 0,1,2,3,4,5 => Change all 2500's value data to 3.

After that run this code.

public static void main(String[] args) throws InterruptedException {

    System.setProperty("webdriver.ie.driver", "D:\\Selenium\\CP-SAT\\IEDriver\\IEDriverServer.exe");

    WebDriver driver = new InternetExplorerDriver();
    driver.get("www.google.com");

It will run on IE. You need a IEDriverServer.exe as i have shown in path, which will run your IE browser.

Reply to me for further query. I ran the above code in eclipse and it ran successfully.

Happy learning :-)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM