How to launch IE browser using selenium webdriver 3.4.0 - selenium

How to launch IE browser using selenium webdriver 3.4.0? I have tried, but unable to open an IE browser. I have downloaded IE Driver and followed the same like launching firefox driver.
Launching of Firefox browser is working fine, below are command lines
System.setProperty("webdriver.gecko.driver","C:\\Users\\vidhya.r\\Desktop\\Automation\\Jars\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
driver = new FirefoxDriver(options);

Download IEDriverServer, put it to path or use
System.setProperty("webdriver.ie.driver", ieDriverPath);
launch via
driver = new InternetExplorerDriver();

DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
capability.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
capability.setCapability(InternetExplorerDriver.ELEMENT_SCROLL_BEHAVIOR, 1);
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
System.setProperty("webdriver.ie.driver", ieDriverPath);
WebDriver driver = new InternetExplorerDriver(capability);

First download IEDriver from this Link
Use this:
System.setProperty("webdriver.ie.driver", "Path of IE driver");
WebDriver driver = new InternetExplorerDriver();
If you want to add some capabilities then use DesiredCapabilities

Related

How to load a specific firefox profile using Selenium webdrivermanager?

I'm trying to use webdrivermanager library to load firefox driver in my selenium tests. I'm unable to load a specific firefox profile using this library. Here is what i'm trying to do:
FirefoxDriverManager.getInstance().setup() // To instantiate the firefox driver
ProfilesIni Prof = new ProfilesIni();
FirefoxProfile profile = Prof.getProfile("C:\\Users\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\6xv9ndwh.SELENIUM");
WebDriver driver = new FirefoxDriver(profile);
But this instantiates a new driver and does not force the driver instantiated by firefoxdrivermanager to use the specific profile.
I tried using default gecko driver too that does not load the profile either. Here is the code that i'm trying:
System.setProperty("webdriver.gecko.driver", "C:\\geckodriver\\geckodriver-v0.20.0-win64\\geckodriver.exe");
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile Profile = allProfiles.getProfile('default');
Profile.setAcceptUntrustedCertificates(true);
Profile.setAssumeUntrustedCertificateIssuer(false);
driver = new FirefoxDriver(Profile);
Can someone help me on this please?
First of all create a new firefox profile
steps for it are
1. Run this command firefox.exe -p in run window
It will show this dialog box create profile with new name and exit the window.
After that perform this command in webdriver
System.setProperty("webdriver.firefox.marionette", "Path to the exe of firefox driver");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("UrProfile Name which u created");
WebDriver driver = new FirefoxDriver(myprofile);
driver.get("http://www.google.com");
Hope it may help u...
This worked for me (though not using webdrivermanager) for instantiating webdriver using Gradle:
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
capabilities.setCapability("acceptInsecureCerts", true);
driver = {new FirefoxDriver(capabilities)}

How to Set capability for IE browser to run in Headless mode

I want to run the scripts in Headless mode for all the 3 browsers Chrome, Firefox & IE
The following is the code for Chrome:
System.setProperty("webdriver.chrome.driver", "./drive/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
options.addArguments("window-size=1400,600");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com/");
Note : Its working fine
Firefox:
FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
System.setProperty("webdriver.gecko.driver", "./drive/geckodriver.exe");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
driver.get("http://www.google.com/");
Note : Its working fine
IE:
Similarly i want to execute in IE with options
IE does not have support for a headless mode (since IE nowadays does not recieve any kind of update or improvements.).
But you can use trifle.js, a kind of browser that can emulate some IE versions in a headless mode, since its coded as a port of PhantomJS.

How to handle untrusted certificate in firefox using Selenium Web Driver?

I'm facing some issues while handling "Untrusted Certificate" in firefox.
We can't use FirefoxDriver(new FirefoxProfile) as it is deprecated
I used the following code but couldn't achieve it.
FirefoxProfile profile=new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
FirefoxOptions options=new FirefoxOptions().setProfile(new FirefoxProfile());
WebDriver driver=new FirefoxDriver(options);
driver.get("Web Link");
Could anyone suggest me the solution to achieve in Selenium 3.
Try this in Firefox
DesiredCapabilities handlSSLErr = DesiredCapabilities.firefox ();
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new FirefoxDriver (handlSSLErr);
driver.get("Your URL link");
For chrome
DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome ();
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new ChromeDriver (handlSSLErr);
driver.get("Your URL link");
Below works fine for me
DesiredCapabilities cap = new DesiredCapabilities().merge(DesiredCapabilities.firefox());
cap.acceptInsecureCerts();
FirefoxDriver driverF = new FirefoxDriver(cap);
driverF.get("https://expired.badssl.com/");

I am writing a Selenium script in Firefox but I am getting "Untrusted Certificate"

written a code like this
FirefoxProfile profile=new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
WebDriver driver=new FirefoxDriver();
driver.get("url");
Not working in firefox how to resolve this one.
You're not creating the driver with the profile - you're creating it with an empty constructor. Try WebDriver driver=new FirefoxDriver(profile);
You can use Selenium WebDriverJS
var WebDriver = require('selenium-webdriver');
var driver = new WebDriver.Builder().withCapabilities(
WebDriver.Capabilities.firefox()
).build();
driver.get('url');

Browser Plugin Testing With Selenium

I am writing a webapp that has a browser plugin component for both firefox and chrome. My current testing system uses a series of Selenium tests created through Selenium IDE.
Is it possible to also have selenium install, activate, and delete browser plugins for firefox and chrome (possibly other browsers as well)?
I think the biggest concern is that installing/enabling the browser plugin requires a browser restart, and I'm not sure if that would through selenium off.
The acquisition of the plugin is easily handled by visiting an internal site-link to a php-script that detects your browser.
The answer is Yes, Selenium 2 supports (remote) installation of browser extensions.
The Chrome and Firefox WebDriver support the installation of extensions, remotely. Here's sample code for Chrome and Firefox:
Chrome
File file = new File("extension.crx"); // zip files are also accepted
ChromeOptions options = new ChromeOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new ChromeDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Firefox
File file = new File("extension.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new FirefoxDriver(firefoxProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
I have also implemented automated installation of Opera and Safari extensions, and they have been merged upstream:
OperaDriver: https://github.com/operasoftware/operadriver/pull/93
SafariDriver: https://github.com/SeleniumHQ/selenium/pull/87
Opera
This API is similar to the FirefoxDriver.
File file = new File("extension.oex"); // Must end with ".oex"
OperaProfile operaProfile = new OperaProfile();
operaProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new OperaDriver(operaProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.profile", operaProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Safari
This API is similar to the ChromeDriver.
File file = new File("extension.safariextz");
SafariOptions options = new SafariOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new SafariDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.safari();
capabilities.setCapability(SafariOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Internet Explorer
Good luck.
Short answer: no
Installing a browser extension is outside of the scope of handling in Selenium.
In Chrome, it displays a modal window that is not "clickable" with Selenium when you want to add a plugin or app. Chrome does not require restarting.
Firefox has the same kind of behaviour to prompt for extension permissions.
You can try something that resides outside of the browser to do what you want. Sikuli might do the trick.