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
}
Related
I want test the IE mode for Edge browser with Selenium. I found the solution on the MS site here:
https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/ie-mode?tabs=java
I am using the following code as given in the above link:
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.attachToEdgeChrome();
ieOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
WebDriver driver = new InternetExplorerDriver(ieOptions);
I can get the error that the methods "attachToEdgeChrome()" and "withEdgeExecutablePath()" are not defined in the InternetExplorerOptions. Is there anything I am missing here?
Note: My selenium jar is selenium-server-4.0.0-alpha-2.jar
As per the ChangeLogs 0f Selenium v4.0.0.0-alpha-2:
Add Chromium-based Edge support. This involves adding a new Chromium driver to the tree too.
So ideally, the code block from the documentation Use Internet Explorer Driver to automate IE mode in Microsoft Edge should have worked seamlessly.
However, as per best practices instead of using the alpha and beta releases, you should always prefer the GA releases to execute your tests and you can pickup anyone from the following options:
Selenium v4.1.3
Selenium v4.1.2
Selenium v4.1.1
Selenium v4.1.0
Selenium v4.0.0
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
I am getting the following error while trying to get selenium webdriver working with robot framework.
WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
I have downloaded the webdriver executable and have put it into path, but am still getting the error.
This is not related to robot framework. If you are able to open firefox using selenium python without giving path of firefox binary then it works fine in robot framework as well.
By default selenium will look into the path - C:\Program Files (x86)\Mozilla Firefox\
Please install firefox using the link - http://filehippo.com/download_firefox/67599/
I had Firefox installed at the default location itself - C:\Program Files (x86)\Mozilla Firefox\, but I was still getting this error. I got it fixed by adding the Firefox location using FirefoxOptions class
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //This is the location where you have installed Firefox on your machine
FirefoxDriver driver = new FirefoxDriver(options);
driver.get("http://www.google.com");
I'm using the latest versions of Selenium, Firefox and GeckoDriver as specified in this article - http://www.automationtestinghub.com/selenium-3-0-launch-firefox-with-geckodriver/
I got the the same error,
For firefox on windows:
put below dir in you Path
C:\Users\abc\appData\Local\Mozilla Firefox\
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");
}
}
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");