I want to perform a click using javascriptexecutor.
JavasciptExecutor jse=(JavascriptExecutor) webDriver;
jse.executescript("arguments[0].click();",webelement)
While running from safari,it is showing "undefined is not a function<evaluating arguments[0].click "
Same works fine in chrome driver.
Am I need to add any capabilities while initiating webDriver?
I have already added capabilities.SetJavascriptEnabled(true). Still it is not working
You have to set the capabilities of driver browserwise.
When running the testcases in safari browser set a global flag for browser. You can create a config file and add "safari" or "chrome" when running it through safari or chrome.
In your source initialize your driver for safari like below :
if (browser.equals("safari")) {
SafariOptions safariOptions = new SafariOptions();
safariOptions.setUseCleanSession(true);
safariOptions.setUseTechnologyPreview(true);
driver = new SafariDriver(safariOptions);
}
Then navigate to your desired url. Here i am adding a sample source for your understanding.
driver.get("https://www.google.com");
WebElement elem = driver.findElement(By.className("gb_P"));
jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].click();", elem);
Hope this will solve your issue. Feel free to comment here for more information.
I want to run the scripts in Headless mode for all the 3 browsers Chrome, Firefox & IE
The following is the code for Chrome:
System.setProperty("webdriver.chrome.driver", "./drive/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
options.addArguments("window-size=1400,600");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com/");
Note : Its working fine
Firefox:
FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
System.setProperty("webdriver.gecko.driver", "./drive/geckodriver.exe");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
driver.get("http://www.google.com/");
Note : Its working fine
IE:
Similarly i want to execute in IE with options
IE does not have support for a headless mode (since IE nowadays does not recieve any kind of update or improvements.).
But you can use trifle.js, a kind of browser that can emulate some IE versions in a headless mode, since its coded as a port of PhantomJS.
I'm using selenium chromedriver for automating web application.
In my application, I need to download xml files. But when I download xml file, I get 'This type of file can harm your computer' pop up. I want to disable this pop up using selenium chromedriver and I want these type of files to be downloaded always. How can this be done?
Selenium version : 2.47.1
Chromedriver version : 2.19
UPDATE it's long standing Chrome bug from 2012.
The problem with XML files started to happen to me as of Chrome 47.0.2526.80 m.
After spending maybe 6 hours trying to turn off every possible security option I tried a different approach.
Ironically, it seems that turning on the Chrome option "Protect you and your device from dangerous sites" removes the message "This type of file can harm your computer. Do you want to keep file.xml anyway?"
I am using 'Ruby' with 'Watir-Webdriver' where the code looks like this:
prefs = {
'safebrowsing' => {
'enabled' => true,
}
}
b = Watir::Browser.new :chrome, :prefs => prefs
Starting the browser like this, with safebrowsing option enabled, downloads the xml files without the message warning. The principle should be the same for Selenium with any programming language.
#####
Edited: 13-04-2017
In latest version of Google Chrome the above solution is not enough. Additionally, it is necessary to start the browser with the following switch:
--safebrowsing-disable-download-protection
Now, the code for starting the browser would look something like this:
b = Watir::Browser.new :chrome, :prefs => prefs, :switches => %w[--safebrowsing-disable-download-protection]))
I am posting below the complete code that got file download working for me:
Hope it helps :-) I am using Java-Selenium
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);
Following Python code works for me
chromeOptions = webdriver.ChromeOptions()
prefs = {'safebrowsing.enabled': 'false'}
chromeOptions.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(chrome_options=chromeOptions)
The accepted answer stopped working after a recent update of Chrome. Now you need to use the --safebrowsing-disable-extension-blacklist and --safebrowsing-disable-download-protection command-line switches. This is the WebdriverIO config that works for me:
var driver = require('webdriverio');
var client = driver.remote({
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: [
'disable-extensions',
'safebrowsing-disable-extension-blacklist',
'safebrowsing-disable-download-protection'
],
prefs: {
'safebrowsing.enabled': true
}
}
}
});
Note that I am also disabling extensions, because they generally interfere with automated testing, but this is not strictly needed to fix the problem with downloading XML and JavaScript files.
I found these switches by reading through this list. You can also see them in the Chromium source.
I came across this recently, using Katalon Studio, Chrome version 88.
Thankfully just the enabling safebrowsing did the trick. You access the settings via "Project Settings" and you navigate to "Desired Capabilities" -> "Web UI" -> "Chrome".
If you don't have a "prefs" setting add it and set the type to Dictionary. Then in the Value add a boolean named "safebrowsing.enabled" and set the value to "true".
Result might look like:
(And you can the default directory setting has nothing to do with this example).
I used all of suggested chrome options in C# and only when my internet connected worked for me but when internet disconnected none of them work for me.
(I'm not sure.may be chrome safebrowsing need to internet connection)
By using older version of chrome(version71) and chromedriver(version 2.46) and after downloading,i saw downloaded XML file name constains 'Unconfirmed' with 'crdownload' extension
and parsing XML file wouldn't work properly.
Finally, creating wait with Thread.Sleep(1000) solved my problem.
IWebDriver Driver;
//chromedriver.exe version2.46 path
string path = #"C:\cd71";
ChromeDriverService driverService = ChromeDriverService.CreateDefaultService(path, "chromedriver.exe");
ChromeOptions options = new ChromeOptions();
// options.AddArgument("headless");
options.AddArgument("--window-position=-32000,-32000");
options.AddUserProfilePreference("download.default_directory", #"c:\xmlFiles");
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("disable-popup-blocking", "true");
options.AddUserProfilePreference("safebrowsing.enabled", "true");
Driver = new ChromeDriver(driverService, options);
try
{
Driver.Navigate().GoToUrl(url);
Thread.Sleep(1000);
//other works like: XML parse
}
catch
{
}
For context, I had a .csv with a list of .swf flash documents and their respective urls. Since the files could only be accessed after a valid login, I couldn't use a simple requests based solution.
Just like .xml, downloading a .swf triggers a similar prompt.
None of the answers worked for me.
So I stripped away all the extra arguments and settings the above answers proposed and just made the chrome instance headless.
options.add_argument("--headless")
prefs = {
"download.default_directory": "C:\LOL\Flash",
"download.prompt_for_download": False,
"download.directory_upgrade": True,
}
options.add_experimental_option("prefs",prefs)
The only workaround that works for me:
Use argument with path to chrome profile
chromeOptions.add_argument(chrome_profile_path)
Search for file download_file_types.pb in chrome profile folder.
In my case ..chromedriver\my_profile\FileTypePolicies\36\download_file_types.pb
Backup this file and then open with any hexeditor (you can use oline).
Search for the filetype you want to download, i.e. xml and change it to anything i.e. xxx
Im using Google Version 80.0.3987.122 (Official Build) (32-bit) and ChromeDriver 80.0.3987.106. Getting the same error even after adding the below while downloading a .xml file.
$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$ChromeOptions.AddArguments(#(
"--disable-extensions",
"--ignore-certificate-errors"))
$download = "C:\temp\download"
$ChromeOptions.AddUserProfilePreference("safebrowsing.enabled", "true");
$ChromeOptions.AddUserProfilePreference("download.default_directory", $download);
$ChromeOptions.AddUserProfilePreference("download.prompt_for_download", "false");
$ChromeOptions.AddUserProfilePreference("download.directory_upgrade", "true");
$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($chromeOptions)
I am trying to start Chrome browser in full screen mode (similar to using F11) on Ubuntu 12.04. I am using the following code, but this doesn't see to work:
if (browser.equalsIgnoreCase("chrome")) {
//Set full screen mode (similar to F11)
ChromeOptions options = new ChromeOptions();
options.addArguments("start-fullscreen");
//Create a new Chrome Driver
System.setProperty("webdriver.chrome.driver","./lib/chromedriver");
this.driver = new ChromeDriver(options);
}
I am using Chrome version 34 with WebDriver version 2.41. Any suggestions?
Linux Mint 16, Chrome version 34.0.1847.132, Selenium 2.41.
Full screen mode works fine.
Try to use:
driver.manage().window().maximize();
to maximize browser window.
Edited.
Also you can try to run chrome in kiosk mode:
ChromeOptions options = new ChromeOptions();
options.addArguments("--kiosk");
driver = new ChromeDriver(options);
This works fine in Linux with Chrome 34.
Or try to press F11 like:
driver.findElement(By.tagName("html")).sendKeys(Keys.F11);
But for me it works fine only in Firefox.
If you're trying to send F11 to the browser, you can probably do it this way:
driver.FindElement(By.TagName("html")).SendKeys(Keys.F11);
I am trying to send F11 to ChromeDriver, however it does not respond to it. When I press F11, it turns Chrome into fullscreen mode. When I send F11 through ChromeDriver, it does not. This is the same for any F-key in ChromeDriver. It works fine with FirefoxDriver and IEDriver, just not ChromeDriver. Is there any way I could get ChromeDriver into fullscreen mode ?
Note : Fullscreen mode is different from maximized mode, as it hides all toolbars.
I was able to solve it using kiosk mode, which keeps the browser in full screen
ChromeOptions options = new ChromeOptions();
options.addArguments("--kiosk");
WebDriver driver = new ChromeDriver(options);
The argument is changed:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
Another option is change the startup script of google-chrome, set start-maximized as default.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-fullscreen");
WebDriver driver = new ChromeDriver(options);
if you use RemoteWebDriver:
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-fullscreen");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
Instance = new RemoteWebDriver(new URL(<SeleniumServerURL>), capabilities);
driver.manage().window().fullscreen();
In my case, i fix the differences between selenium webdriver coordinates and screen absolute coordinates (root cause: chrome tab, header and address field size are ignored by selenium .getcoordinate mechanism) by this way:
String shortcutGoToFullScreen = Keys.chord(Keys.F11);
WebDriver.findElement(By.tagName("body")).sendKeys(shortcutGoToFullScreen);
Only one problem, that this fullscreen mode became non full after any page code updates. So, it should be used carefully )
Use --start-fullscreen argument to Specify the browser should start in fullscreen mode, like if the user had pressed F11 right after startup.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-fullscreen");
WebDriver driver = new ChromeDriver(options);
You can change the behavior as you prefer by providing arguments to ChromeOptions.
Following link gives you in detail view of arguments and their behaviour. Hope it helps.
https://peter.sh/experiments/chromium-command-line-switches/#start-fullscreen
With Powershell/Selenium I wrote the script:
$Driver = Start-SeChrome -Fullscreen -StartUrl "https://........."
This worked perfectly for me