How can i set the Property strictFileInteractability - selenium

geckodriver 0.24.0 introduces the capability strictFileInteractability see below,
but I haven't found a possibility to set this capability.
Code trials:
FirefoxProfile profile=new FirefoxProfile();
// Has no effect
profile.setPreference("strictFileInteractability", true);
...
FirefoxOptions options = new FirefoxOptions();
// Has no effect
options.setCapability("strictFileInteractability", true);
...
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
// Has no effect
capabilities.setCapability("strictFileInteractability", true);
Did someone manage to successfully set this capability?
Changelog:
github.com/mozilla/geckodriver/releases
w3c.github.io/webdriver/

GeckoDriver v0.24.0 introduced us to strictFileInteractability capability.
As per the Capabilities section within WebDriver W3C Living Document:
Capability Key Value Type Description
---------- --- ---------- -----------
Strict file interactability "strictFileInteractability" boolean Defines the current session’s strict file interactability.
As per the discussion Add support for 'strictFileInteractability' W3C capability strictFileInteractability capability was added from [java] Adding a type-safe option for strictFileInteractability capability pull request.
Example
Using Java, Option Class and Firefox:
Code Block:
System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
FirefoxOptions opt = new FirefoxOptions();
opt.setCapability("strictFileInteractability", true);
FirefoxDriver driver = new FirefoxDriver(opt);
driver.get("https://www.google.com/");
System.out.println(driver.getTitle());
driver.quit();
Console Output:
Google
Using Java, DesiredCapabilities Class and Firefox:
Code Block:
System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("strictFileInteractability", true);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
FirefoxDriver driver = new FirefoxDriver(opt);
driver.get("https://stackoverflow.com");
System.out.println("Page Title is : "+driver.getTitle());
driver.quit();
Console Output:
Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers

Related

How to handle or supress warning in Katalon for Chrome browser "This type of file can harm you computer. Do you want to keep it anyway?"

I want to suppress the above alert mentioned in the title while running my Katalon scripts.
Attaching screenshots for same:
It possible we have to run the chromedriver in safe mode.please try the below code
System.setProperty("webdriver.chrome.driver", "C:/chromedriver/chromedriver.exe");
String downloadFilepath = "D:/MyDeskDownload";
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
chromePrefs.put("safebrowsing.enabled", "true");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(cap);
You can set up the browser to automatically download files. The following is taken from Katalon forum:
First you add Chrome preferences:
HashMap<String, Object> chromePrefs = new HashMap<String, Object>()
chromePrefs.put("download.default_directory", downloadPath)
chromePrefs.put("download.prompt_for_download", false)
And then specify the path to ChromeDriver and add experimental options:
System.setProperty("webdriver.chrome.driver", "DriverFactory.getChromeDriverPath()")
ChromeOptions options = new ChromeOptions()
options.setExperimentalOption("prefs", chromePrefs)
NOTE:
You will need to import the following (or press CTRL+SHIFT+O for automatic imports):
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import com.kms.katalon.core.webui.driver.DriverFactory

FirefoxDriver() does not accept ProfilesIni instance as argument

I'm following the example on this page to set up a custom profile to use:
http://toolsqa.com/selenium-webdriver/custom-firefox-profile/
However in my code I'm getting "Remove argument to match Firefox driver" error:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("testProfile");
WebDriver driver = new FirefoxDriver(myprofile); // does not like myprofile as an argument here
Thanks
UPDATE
I was able to resolve this issue by slightly modifying try-catch's solution:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("testProfile"); //added this
FirefoxOptions options = new FirefoxOptions();
options.setProfile(myprofile);
According to the API docs of FirefoxDriver there's no FirefoxDriver(ProfilesIni) signature and ProfilesIni has no base class nor implements an interface that is available as a constructor signature to FirefoxDriver.
Through there's a FirefoxDriver(FirefoxOptions) signature. And FirefoxDriver has a setProfile(FirefoxProfile profile) method.
This should work:
ProfilesIni profile = new ProfilesIni();
FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile.getProfile("testProfile"));
WebDriver driver = new FirefoxDriver(options);

Selenium 3.6.0 & webdriver = new FirefoxDriver(capabilities) - deprecated?

Since upgrading to the latest version of Selenium the following code seems to be deprecated:
Selenium 3.6.0 & webdriver = new FirefoxDriver(capabilities) - deprecated?
Full code:
System.setProperty("webdriver.gecko.driver", Base_Page.getConstant(Constant.GECKO_DRIVER_DIRECTORY));
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
webdriver = new FirefoxDriver(capabilities); //deprecated
From https://raw.githubusercontent.com/SeleniumHQ/selenium/master/rb/CHANGES
3.4.1 (2017-06-13)
==================
Firefox:
* Added new Firefox::Options class that should be used to customize browser
behavior (command line arguments, profile, preferences, Firefox binary, etc.).
The instance of options class can be passed to driver initialization using
:options key. Old way of passing these customization directly to driver
initialization is deprecated.
From the 3.4.1 version the FirefoxOptions should be used.
Changed the following code 'FirefoxDriver(capabilities) to firefoxOptions which uses .setCapcability()
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setCapability("marionette", true);
webdriver = new FirefoxDriver(firefoxOptions);
Try following:
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(firefoxOptions);
You can try this line;
FirefoxOptions ffOpt = new FirefoxOptions();
ffOpt.setCapabilities("marionette", true);
WebDriver driver = new FirefoxDriver(ffOpt);

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/");

Migrating from Firefox WebDriver to Marionette

I am trying to switch from FireFoxDriver to MarionetteDriver.
I managed to run firefox with MarionetteDriver by running:
public void runMarionnete(){
DesiredCapabilities dc = DesiredCapabilities.firefox();
OSUtils.setProperty("webdriver.firefox.bin", "C:\\Firefox\\firefox.exe");
OSUtils.setProperty("webdriver.gecko.driver","C:\\Drivers\\wires-0.6.2-win.exe"));
_driver = new MarionetteDriver(dc);
}
But I have 2 things I am not sure how to do:
1.How to add XPI extensions to the driver ?
in the old way I used:
FirefoxProfile.addExtension ...
2.How to configure all the firefox properties , like I used to do , for example:
profile.setPreference("browser.startup.homepage;about:home","about:blank");
profile.setPreference("startup.homepage_welcome_url","about:blank");
profile.setPreference("browser.usedOnWindows10.introURL","about:blank");
profile.setPreference("devtools.devedition.promo.url","");
profile.setPreference("xpinstall.signatures.required",false);
Thank you!
You can use the same FirefoxProfile class, just add it to the DesiredCapabilities in the following way:
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.startup.homepage;about:home","about:blank");
firefoxProfile.setPreference("startup.homepage_welcome_url","about:blank");
firefoxProfile.setPreference("browser.usedOnWindows10.introURL","about:blank");
firefoxProfile.setPreference("devtools.devedition.promo.url","");
firefoxProfile.setPreference("xpinstall.signatures.required",false);
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
desiredCapabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);