Unable to launch IE browser in selenium webdriver

2020-02-26 11:47发布

I have written a sample code to launch IE browser and load google page.

public class Sample {

 public static void main(String[] args) 
  {
    // TODO Auto-generated method stub
    System.setProperty("webdriver.ie.driver","H:/IEDriverServer.exe");
    WebDriver driver=new InternetExplorerDriver();
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

    driver.get("http://www.google.com");
  }
}

But when I run this script it launches browser and it gets closed immediately (less than 2 sec) without prompting any error and the script wont terminates.

This is what I can see on console screen:

Started InternetExplorerDriver server (32-bit)

2.53.1.0

Listening on port 46974

Only local connections are allowed

Can any one help me on this issue?

7条回答
等我变得足够好
2楼-- · 2020-02-26 12:17

I completely agree with sandeep's solution along with that for setting zoom level to 100% permanently i am adding few code lines as i faced issue to set this.

These are the code lines i found after i browsed for the zoom level 100% error:

System.setProperty("webdriver.ie.driver", "C:/Drivers/IEDriverServer.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability("ignoreZoomSetting", true);
driver= new InternetExplorerDriver(capabilities);           
driver.manage().window().maximize();

For the security settings to execute code through IE : follow the steps in this link.` 'http://www.seleniumeasy.com/selenium-tutorials/how-to-run-webdriver-in-ie-browser'

Hope this solution helps you.... :)

查看更多
戒情不戒烟
3楼-- · 2020-02-26 12:28
package tests;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class Sample {

    public static void main(String[] args) {
        System.setProperty("webdriver.ie.driver","C:\\Automation Workspace\\ComplianceDashboardProject\\Vendor\\IEDriverServer.exe");
        WebDriver driver=new InternetExplorerDriver();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

        driver.get("http://www.google.com");
        driver.quit();
    }
}

I did the above and got it to work. Maybe try moving your driver file to another location to make sure there isn't some security issue.

查看更多
叛逆
4楼-- · 2020-02-26 12:29

Disabled JavaScript on IE can cause the test to not run.

I keep reading answers to set security setting to anything as long as it's consistent, but I find it's best to set them all to Medium, as this security level won't disable JavaScript. But in any case, if one has this issue, he can choose "Custom level..." for the "Internet" option in the Security tab, and make sure that "Active Scripting" under "Scripting" is enabled.

Of course, first make sure to complete all the steps in the IEDriver docs.

查看更多
Luminary・发光体
5楼-- · 2020-02-26 12:34

try:

public static void main(String[] args) 
{
    try
    {
       string path = @"H:\IEDriverServer.exe";
       WebDriver driver = new InternetExplorerDriver(path);
       driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
       driver.manage().window().maximize();

       driver.get("http://www.google.com");
    }
    catch(Exception ex)
    {
    }
}
查看更多
Ridiculous、
6楼-- · 2020-02-26 12:35

If your IE version is 11, There are following steps to resolve it :-

  • Registry entries for 32 and 64 bit.

create a DWORD value with the name "iexplore.exe" and the value of 0 in the following key

for 32-bit Windows :- HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE

for 64-bit Windows :- HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
  • Adjusted "Protected Mode" to be the same for all security zones by navigating through Settings -> Internet Options -> Security
  • Unchek "Enable Protected Mode" for all zones
  • Even rebooted.

If still getting the problem Add domain to list of "Trusted Sites" for i.e. in "Internet Options" (https to trusted sites, and http to local intranet).

Hope it will help you..:)

查看更多
迷人小祖宗
7楼-- · 2020-02-26 12:38

Below steps are worked for me, Hope this will work for you as well:

  1. Open internet explorer.
  2. Navigate to Tools->Option
  3. Navigate to Security Tab
  4. Now for all option like Internet,Intranet,Trusted Sites and Restricted Site enable "Enable Protected" mode check-box.
  5. Set IE zoom level to 100%
  6. Click on Apply and OK
  7. Close the IE browser and run your script
查看更多
登录 后发表回答