I am trying to get IE to start each session clean when intializing a remote driver via the Selenium grid. This
DesiredCapabilities caps = null;
caps = DesiredCapabilities.internetExplorer();
caps.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
WebDriver driver = new RemoteWebDriver(new URL("http://10.10.22.126:5555/wd/hub"), caps);
is not working, IE is starting each new test with the cookies from the previous test, which causes issues. I am trying to implement this
InternetExplorerOptions ieOptions = new InternetExplorerOptions()
.destructivelyEnsureCleanSession();
As dictated here, but I can't figure out how to use this as a remote driver instead of locally. Thanks!
You can set the option as a capability in somewhat this manner:
InternetExplorerOptions ieOptions = new InternetExplorerOptions()
.destructivelyEnsureCleanSession();
capabilities.setCapability("se:ieOptions", ieOptions);
The InternetExplorerOptions class defines the constant for this capability as:
private final static String IE_OPTIONS = "se:ieOptions";
Related
There are currently two recommended ways to launch the latest version of Selenium using a specific profile. One is through the Desired Capabilities object and the other us by using Firefox Options.
Desired Capabilities:
public static WebDriver launchFirefoxProfileByFFCapabilities()
{
WebDriver driver = null;
System.setProperty("webdriver.gecko.driver", "PATH");
ProfilesIni profile = new ProfilesIni();
String profileName = "Profile_1";
FirefoxProfile firefoxProfileByProfilesIni = profile.getProfile(profileName);
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, firefoxProfileByProfilesIni);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
driver = new FirefoxDriver(opt);
return driver;
}
Firefox Options:
public static WebDriver launchFirefoxProfileByFFOptions()
{
WebDriver driver = null;
System.setProperty("webdriver.gecko.driver", "PATH");
ProfilesIni profile = new ProfilesIni();
String profileName = "Profile_1";
FirefoxProfile firefoxProfileByProfilesIni = profile.getProfile(profileName);
FirefoxOptions opt = new FirefoxOptions();
opt.setProfile(firefoxProfileByProfilesIni);
driver = new FirefoxDriver(opt);
return driver;
}
I noticed a few interesting discrepancies between the two approaches and I'm trying to understand what is the reason for these discrepancies and how to prevent them.
1) With Firefox Options when the specified Profile Name does not exist (as it appears in the Firefox - Choose User Profile dialog) throws WebDriverException: Unexpected value for profile: null. However with Desired Capabilities no such exception is thrown and Selenium silently ignores the profile preference (which is not ideal)
2) If the Profile Name exists (as it appears in the Firefox - Choose User Profile dialog) but the path in profiles.ini file is incorrect even Firefox Options will launch silently ignore the profile preference and launch WebDriver not connected to any profile
What is the cause of these discrepancies? How can they be prevented?
Thanks
It seems that Capabilities and FirefoxProfile/FirefoxOptions handle the profileIni in a different way.
Could you please modify and add the stack-traces so we can further help you?
I am using selenium to autofill the form fields through internet explorer.But what is happening it is taking to long to fill the required fields. Is there any way by which we can increase the speed.
Here is the code:
System.setProperty("webdriver.ie.driver","C:\\Users\\mayank\\Desktop\\IEDriverServer.exe");
WebDriver driver=new InternetExplorerDriver();
driver.get("http://online.newindia.co.in");
driver.findElement(By.name("loginid")).sendKeys("abc");
driver.findElement(By.name("password")).sendKeys("xyz");
driver.findElement(By.id("login")).click();
DesiredCapabilities ieCaps = DesiredCapabilities.internetExplorer();
ieCaps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
ieCaps.setCapability("requireWindowFocus", true);
driver = new InternetExplorerDriver(ieCaps);
add these four lines
I am currently trying to write a test that tests the non-JS version of my website. I use Selenium with Java. I have tried this:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("javascript.enabled", false);
driver = new FirefoxDriver(profile);
driver.get();
However this isn't working. It just loads the page with JavaScript Enabled.
As a workaround I did, this, for the requirement.
It will manually set the javascript.enabled property to false by the following script.
WebDriver driver = new FirefoxDriver();
driver.get("about:config");
Actions act = new Actions(driver);
act.sendKeys(Keys.RETURN).sendKeys("javascript.enabled").perform();
act.sendKeys(Keys.TAB).sendKeys(Keys.RETURN).perform();
When running plain PhantomJS a config.json can be set which sets some options. How I can setup PhantomJS with JSON file when using the Selenium WebDriver?
I have this:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("takesScreenshot", false);
caps.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"/usr/local/bin/phantomjs");
driver = new PhantomJSDriver(caps);
In plain PhantomJS a --config=config.json commandline option can be specified when running it as seen here. The same can be specified when invoking PhantomJS through the selenium webdriver by passing this commandline option through the capabilities:
ArrayList<String> cliArgsCap = new ArrayList<String>();
cliArgsCap.add("--config=config.json");
DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
capabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
capabilities.setCapability("takesScreenshot", false);
capabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"/usr/local/bin/phantomjs");
WebDriver driver = new PhantomJSDriver(capabilities);
This is adapted from my answer here.
How can I click accept/dismiss unhandledalerts with WebDriver?
Is it possible to check where the unhandled alerts are coming?
How can I use UNEXPECTED_ALERT_BEHAVIOUR capability? It is not working as I expected?
I've tried like this
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, "Accept");
Try this code:
WebDriver driver;
#BeforeClass
public void setUp() {
DesiredCapabilities dc=new DesiredCapabilities();
dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,UnexpectedAlertBehaviour.ACCEPT);
driver =new FirefoxDriver(dc);
}
I hope this would be helpful to you.
Open Firefox and try 'about:config'.
Findout which Preference Name can solve you problem and set values accordingly using below code. example: I am disabling automatic update of Firefox.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("app.update.enabled", false);
WebDriver driver = new FirefoxDriver(profile);