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();
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'd like to know if the method shared here: Selenium webdriver: Modifying navigator.webdriver flag to prevent selenium detection it's still currently working and if yes I'd like to know how to do the same using Java on geckodriver.
Since now I tried the following without success:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("dom.webdriver.enabled","False");
profile.setPreference("useAutomationExtension","False");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);
String user = System.getProperty("user.name");
System.setProperty("webdriver.gecko.driver", "/Users/" + user + "/Desktop/Configs/geckodriver");
FirefoxDriver driver = new FirefoxDriver(options);
driver.executeScript("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})");
driver.get("https://mysite/");
But typing navigator.webdriver in console still returns True
While automating the web page which includes Vidyo Web player plugin.
If I am navigating to the Video page, the allow pop-up is showing.
I have tried to with the below code to handle allow pop-up. But it's not working.
Below is the code which am using,
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("security.mixed_content.block_active_content", true);
profile.setPreference("security.mixed_content.block_display_content", false);
WebDriver driver = new FirefoxDriver(profile);
Can any one help on this?
Thanks in Advance.
Referencing this answer, you probably need to source the file for the extension and use the below:
File file = new File("path to extension file");
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(file);
WebDriver driver = new FirefoxDriver(profile);
How about this preference:
FirefoxProfile profile= new FirefoxProfile();
profile.setPreference(“browser.popups.showPopupBlocker”, false);
WebDriver driver = new FirefoxDriver(profile);
Try to set this preference to get rid of "Allow"/"Continue Blocking":
profile.setPreference("plugin.scan.plid.all", false);
Also you might need to use this to automatically allow extension
profile.setPreference("extensions.blocklist.enabled", false);
I want to modify a firefox template from which webdriver will create temporary profile by
new FirefoxDriver();
I am linux user (ubuntu). Anybody knows where this template is located?
We don't modify the actual file in our solution.
Granted, this is C#, but it should be very similar:
FirefoxProfile profile = new FirefoxProfile() {AcceptUntrustedCertificates = true};
profile.SetPreference("webdriver_assume_untrusted_issuer", false);
Driver = new FirefoxDriver(profile);
Driver.Manage().Window.Maximize();
I want to disable the geolocation permissions for a website using firefox capabilities in selenium webdriver, but i am not able to do so.
I tried doing this...
WebDriver d = null;
cap = cap.merge(DesiredCapabilities.firefox());
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("geo.enabled", false);
cap.setCapability("geo.provider.use_corelocation", false);
cap.setCapability("geo.prompt.testing", false);
cap.setCapability("geo.prompt.testing.allow", false);
Attached is the screenshot of the same
I haven't tried with your specific parameter but for others it works well, like this:
FirefoxProfile profile = new FirefoxProfile();
// Turn off updates
profile.setPreference("app.update.enabled", false);
WebDriver driver = new FirefoxDriver(profile);
Using Selenium 2.48 and FF 42.0 (but it should do for other versions, as well.
This worked for me
caps.setCapability("locationContextEnabled", false);