Loading Edge 83 with Selenium, in EdgeHTML mode (UseChromium = false). Returns Error - selenium

I'm trying to launch Edge using the EdgeHTML renderer mode, within Selenium, using Visual Studio C#.. I'm using the version 83.0.478.58 (64bit) and the driver 83.0.478.58 (64bit). Installed via nuget.
If I launch the browser using it works fine...
EdgeOptions options = new EdgeOptions();
options.UseChromium = true;
options.AddUserProfilePreference("download.default_directory", #"C:\temp\");
EdgeDriver edgeDriver = new EdgeDriver(options);
By default UseChromium is False, which should launch the browser in the EdgeHTML renderer. If I use the below code it will error out.
EdgeOptions options = new EdgeOptions();
options.AddUserProfilePreference("download.default_directory", #"C:\temp\");
EdgeDriver edgeDriver = new EdgeDriver(options);
The browser will open a new instance, but once the browser is open. The code bugs out and returns the error message,
OpenQA.Selenium.WebDriverException: 'The new session command returned a value ('Unknown error') that is not a valid JSON object.'
If I just try and simply initialise without the options, I still get the same error.
Anyone got any ideas? Looking around I see documentation and guides all over that launch the browser without UseChromium.
Cheers

Looks like you are trying to set the default download directory for the MS Edge legacy (EdgeHTML) browser using the Selenium code.
I want to inform you that it is possible to set the default download directory for the MS Edge (Chromium) browser as you had already tried that successfully but it is not possible to set the default download directory for the MS Edge legacy (EdgeHTML) browser using the Selenium code.
As a workaround, you can try to set the download directory manually.
References:
Change the default file download path for Edge using selenium
Change default download location in Edge

Related

How to handle Window Based PDF

I've scenario like when clicking on one button its opening a Window Based PDF File:
I'm using Gecko driver Version -21.0 Firefox Version -61.0.1 Selenium Stand alone Server -3.13
I'm unable to switching to the window based PDF File getting error:
java.net.SocketException: Software caused connection abort: recv failed in Result
The above error is coming for "driver.getWindowHandles()" method
It's working for Chrome and IE but when I'm using Gecko driver Version - 20.1, I'm able to Switching the Window Based PDF.
Can anyone help me with this?
I want to handle it by using latest gecko driver -21.0
Unfortunately, it is difficult to perform operations on pdf by switching tabs. The best way is to download the pdf and perform operations on the downloaded file using some java library or pdf-parser.
This usual behaviour of pdf is due to an enabled feature of pdf js. Disabling that in the firefox profile may solve your issue
Update your Firefox profile solves this issue.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference( "pdfjs.disabled", true );
profile.setPreference("pdfjs.disabled", true );
profile.setPreference("pdfjs.enabledCache.state", false );
profile.setPreference("pdfjs.enabledCache.state", false);
profile.setPreference("pdfjs.migrationVersion", 2);
profile.setPreference("pdfjs.previousHandler.alwaysAskBeforeHandling", true);
profile.setPreference("pdfjs.previousHandler.preferredAction", 4);
FirefoxOptions options = new FirefoxOptions().setProfile(profile);
WebDriver driver = new FirefoxDriver(options);
which stops the pdf opening in new window and further you can implement a method to download the file and parse the downloaded file.
Hope this helps you :)

SpecFlow Selenium run on local webpage with Chrome

I'm learning how to use SpecFlow with Selenium in Visual Studio 2015. I finished creating a simple webpage that has checkbox on it. Now I want to use SpecFlow with Selenium to test the checkbox selection. Since the webpage is HTML file and locally on my computer also Selenium does not have ChromeDriver version correctly, so I have to download the ChromeDriver to locally and copy the exe file to C:\Temp\SpecFlowDemo\packages folder.
Below is the code and I think the problem is using "BinaryLocation". I've searched online, but most posts I have seen, they use "setBinary" method, but based on the ChromeDriver version I have, "setBinary" does not exist. So I find "BinaryLocation" is the closest that I can use. But when I run the test via Visual Studio, it says "OpenQA.Selenium.DriverServiceNotFoundException: the chromedriver.exe file does not exist in the current directly" I already copy chromedriver.exe into my C:\Temp\SpecFlowDemo\packages folder. So not sure what is the issue.
IWebDriver webDriver;
ChromeOptions optionChrome;
[Given(#"There are five selections avaiable")]
public void GivenThereAreFiveSelectionsAvaiable()
{
string driverExe = #"C:\Temp\SpecFlowDemo\packages";//my SpecFlow project named SpecFlowDemo created with Visual Studio 2015
//initialize driver
optionChrome = new ChromeOptions();
optionChrome.AddArgument("--allow-file-access-from-files");
optionChrome.BinaryLocation = driverExe;//setBinary() does not exist
webDriver = new ChromeDriver(optionChrome);
webDriver.Navigate().GoToUrl(#"C:\Projects\WebDemo\index.html");//my webpage project
}

Unable to launch URL in edge browser - Selenium Java

I am trying to automate in Microsoft edge browser. I referred to the below links to do it and I am able to launch the browser, but it's failing to launch the URL. Can someone please help me.
Selenium Java version : 2.53.1
Tried with both of the edge drivers(insider version and webdriver), one returned null exception and not launching any browser and the other is returning unknown error after launching the browser.
https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Code referred from:
stackoverflow.com/questions/31991309/selenium-on-windows-10-edge-browser
You would need to download the correct version of Edge Driver based on the OS build number. I faced this issue when I used Edge driver version which was different from my build number.
Follow the below steps (I have tried this with Selenium 3.0 Beta1 and its working fine)
Use the steps given below -
Go to Start > Settings > System > About and note down the OS Build number
Download the proper version of the driver from this link - https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
If the file that's downloaded is .msi, then install it to get the .exe driver. For one of the release, direct .exe can be downloaded.
Once the MicrosoftWebDriver.exe is downloaded, we can use it in our test script using either System.setProperty("webdriver.edge.driver", "driver location") or using environment variable
Sample Script :
System.setProperty("webdriver.edge.driver","C:\\Program Files (x86)\\Microsoft Web Driver\\MicrosoftWebDriver.exe"); //put actual location
WebDriver driver = new EdgeDriver();
driver.get("your link");
Refer this article for detailed information: http://automationtestinghub.com/selenium-3-launch-microsoft-edge-with-microsoftwebdriver/
Note : Edge browser version should be 18 or 19
This solution worked for me was by enabling Developer Mode in Windows OS:
Go to Settings -> Windows Update settings ->For Developers -> Enable Developer Mode
Run Test Script :
public class IETest {
public static void main(String[] args)
{`enter code here`
WebDriver obj=new EdgeDriver();;
obj.navigate().to("http://www.google.com");
}
}

Selenium chromedriver won't launch URL if another chrome instance is open

I tried to load chrome profile using selenium weDriver. The profile loads fine but it failed when it tries to load the URL.
I noticed that this issue happens when there is another chrome instance open whether or not it was open by webDriver. I have selenium 2.53.1.
System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:/Users/useName/AppData/Local/Google/Chrome/User Data");
options.addArguments("--start-maximized");
driver = new ChromeDriver(options);
driver.get("www.google.com") // here is where it fails. It works fine if I close all chrome browsers before I run the test
I found a workaround for this issue. I noticed that this issue happens because chromedriver will not be able to launch with the same profile if there is another open instance using the same profile. For example, if chrome.exe is already open with the default profile, chromedriver.exe will not be able to launch the default profile because chrome.exe is already open and using the same profile.
To fix this, you will need to create a separate profile for automation by copying the default profile so that chromedriver.exe and chrome.exe don't share the same default profile.
The default chrome profile is in this location:
C:\Users\yourUserName\AppData\Local\Google\Chrome\User Data\
Copy all files from User Data folder to a new folder and call it AutomationProfile
After you copy the files to the new folder then you can use it for your scripts.
String userProfile= "C:\\Users\\YourUserName\\AppData\\Local\\Google\\Chrome\\AutomationProfile\\";
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir="+userProfile);
options.addArguments("--start-maximized");
driver = new ChromeDriver(options);
Make sure you use driver.quit() at the end of your test so that you don't keep chromedriver.exe open
I added the ChromeOption "no-sandbox", and it seemed to help me with a similar issue. Know that this changes how secure your browsing can be. Here's a link that explains it more: https://www.google.com/googlebooks/chrome/med_26.html
var options = new ChromeOptions();
//I had more options added, but this is the example of the argument I referred to
options.AddArgument("no-sandbox");

Could not locate Firefox on the current system (Firefox 47)

After the Firefox self-upgraded to version 47, Selenium stopped working.
I followed the Javascript (Node.js) steps suggested by Mozilla regarding the Marionette driver, but the console says that it can't find Firefox on my current system, however the path to the browser is fine and standard.
The error is "Could not locate Firefox on the current system"
at C:\Users\\node_modules\selenium-webdriver\firefox\binary.js:115:11
If it matters, I use WebdriverJS.
I've had this happen and it always seems to be very random. This is a long shot but try changing the path and then putting the original back this has worked for me in the past.
I'm having a similar problem and see that there seem to be a wealth of problems with Firefox 47 and WebDriver (JS and other languages) being discussed in the GG group. Your only solution for now might be to downgrade - https://ftp.mozilla.org/pub/firefox/releases/46.0.1/
Admittedly, downgrading did not solve my problem, but ymmv
I had the same problem and solved it by downloading the Developer Edition from https://www.mozilla.org/en-US/firefox/developer/. Apparently there is some conflict regarding using the developer edition of firefox.
In node_modules/selenium-webdriver/firefox/binary.js, line 99, this code :
let exe = opt_dev
? '/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox-bin'
: '/Applications/Firefox.app/Contents/MacOS/firefox-bin';
found = io.exists(exe).then(exists => exists ? exe : null);
chose the DeveloperEdition, but I didn't have it, which caused found to be null and later an error is thrown in line 115.
Could it be that your Firefox is not installed in the default location? Mine is installed in C:\Users\(username)\AppData\Local\Mozilla Firefox\, and I get the same error message as you.
Browsing the code (thanks #achie), I found the following in node_modules\selenium-webdriver\firefox\index.js:
* On Windows and OSX, the FirefoxDriver will search for Firefox in its
* default installation location:
*
* * Windows: C:\Program Files and C:\Program Files (x86).
* * Mac OS X: /Applications/Firefox.app
*
* For Linux, Firefox will be located on the PATH: `$(where firefox)`.
In other words, it's not even any use to put the Firefox directory in the PATH variable on Windows.
But the source code continues:
* You can configure WebDriver to start use a custom Firefox installation with
* the {#link Binary} class:
*
* var firefox = require('selenium-webdriver/firefox');
* var binary = new firefox.Binary('/my/firefox/install/dir/firefox-bin');
* var options = new firefox.Options().setBinary(binary);
* var driver = new firefox.Driver(options);
In my case, that becomes:
var firefox = require('selenium-webdriver/firefox');
var binary = new firefox.Binary('C:\\Users\\(username)\\AppData\\Local\\Mozilla Firefox\\firefox.exe');
var options = new firefox.Options().setBinary(binary);
var driver = new firefox.Driver(options);
Now Selenium finds my Firefox, but I get a next error message:
Error: Timed out waiting for the WebDriver server at http://127.0.0.1:53785/hub
I also tried var driver = new webdriver.Builder().forBrowser('firefox').setFirefoxOptions(options).build();, but that didn't make any difference.
Hope this helps you a bit further!
The folks at Mozilla are recommending using the Marionette driver as there is a start up crash issue with Selenium Webdriver 2.53 and Firefox 47/48
https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver
The latest Firefox 48 and Selenium Webdriver 3.0.0 solved this particular issue.