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.
Related
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";
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();
Is their a way to pre-define a language for webpage? I want to load google page in Spanish, can we set property of webdriver in such a way that it load the page in Spanish.
Check this link:
For Firefox:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference( "intl.accept_languages", "es" );
WebDriver driver = new FirefoxDriver(profile);
For Chrome:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--lang=es");
ChromeDriver driver = new ChromeDriver(options);
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);
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);