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);
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();
How to use this method? What parameter should I pass to "capabilityName" and "value"?
public void setCapability(java.lang.String capabilityName,java.lang.String value);
For Chrome specifically, you can find the capabilities here: https://sites.google.com/a/chromium.org/chromedriver/capabilities-aka-chromeoptions
There is a more general overview of capabilities on the selenium wiki: http://code.google.com/p/selenium/wiki/DesiredCapabilities
Here is an example that maximizes the browser window (for chrome). Enable/Disable the second while running it and see the difference.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com");
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);