Unable to launch URL in edge browser - Selenium Java - selenium

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");
}
}

Related

The method attachToEdgeChrome() is undefined for the type InternetExplorerOptions using selenium-server-4.0.0-alpha-2

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

Install and use Geckodriver on Heroku correctly [duplicate]

from selenium import webdriver;
browser= webdriver.Firefox();
browser.get('http://www.seleniumhq.org');
When I try to run this code, it gives me an error 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.
Any thoughts-highly appreciated!
This error 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.
...implies that the GeckoDriver was unable to find the Firefox binary at the default location. Additionally you haven't passed the moz:firefoxOptions.binary capability.
Solution
Possibly within your system firefox is installed in a custom location and these cases you need to pass the absolute path of the Firefox binary through the moz:firefoxOptions.binary capability as follows:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe'
driver = webdriver.Firefox(executable_path=r'C:\WebDrivers\geckodriver.exe', options=options)
driver.get('http://google.com/')
References
You can find a couple of relevant detailed discussion in:
SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary'
InvalidArgumentException: Message: binary is not a Firefox executable error using GeckoDriver Firefox Selenium and Python
Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided
Firefox was not installed on my system at all. That's why this error came up.
same issue here:
Environment
OS: Mac
Not install Firefox application
has installed geckodriver, can found in PATH
Error Reason: Not installed Firefox
Solution: (goto firefox official site to download and) install Firefox
Before this ensure that path variable has include for geckodriver click here to download driver and run below python script.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe'
driver = webdriver.Firefox(options=options)
driver.get('http://google.com/')
I have uninstalled firefox and installed it again which resolved my issue.
You should download appropriate web driver from https://github.com/mozilla/geckodriver/releases and put it into folder where your py file is. Also you can put it anywhere as long as the location of the file it is in your system path.
Selenium uses a web driver (a specific one for each web browser) in order to communicate with the browser installed on your system (Firefox in your case).
To use Firefox, you have to:
Download its web driver from
https://github.com/mozilla/geckodriver/releases
Put the web driver in a specific location in the file system (same folder as the python script for example)
Add the web driver location path when initializing in the python code.
So the final code would look like this:
from selenium import webdriver
browser = webdriver.Firefox('./geckodriver')
browser.get('https://www.python.org/')
Note: Sometimes a newer version of the web driver isn't compatible with an older version of the browser installed on your system.
I have encountered the same problem (Windows, Firefox v99, Selenium 4.1.4, geckodriver 0.31.0), the path to exe file and the driver initialisation were set correctly, solved the issue by changing the win32 by win64 version of geckodriver
as a side note for selenium/firefox (but with C#, not Python), this issue is quite relevant now in the sense that firefox location looks to be stored in windows in a new regedit location. Indeed geckodriver is looking in regedit location documented here:
HKEY_LOCAL_MACHINE\SOFTWARE WOW6432Node\Mozilla\Mozilla Firefox\[VERSION]\Main\PathToExe
HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox\[VERSION]\Main\PathToExe
Source:
https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions
when on my machine it is there:
HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox 109.0\bin
With the version number stored here:
HKEY_LOCAL_MACHINE\SOFTWARE\mozilla.org\Mozilla
and I set the selenium driver with C# Api with (path hardcoded for the poc):
var options = new FirefoxOptions();
...
options.BrowserExecutableLocation = #"C:\Program Files\Mozilla Firefox\firefox.exe";
Driver = new FirefoxDriver(options);
Regards
You need to download geckodriver.
https://github.com/mozilla/geckodriver/releases
from selenium import webdriver;
browser= webdriver.Firefox('./geckodriver');
browser.get('http://www.seleniumhq.org');

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
}

Selenium/Chromedriver automation hanging when run as executable

I am trying to create a simple automation task. For now I want to log in to the webpage. This all works fine when I run the test in Visual Studio 2017. However this will need to be executed as an exe on regular interval in windows system. When I run the executable it hangs after displaying:
Starting ChromeDriver 2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a)
on port 9515
Only local connections are allowed.
I understand this is just info not an error per most SO posts related to this issue such as - When running WebDriver with Chrome browser, getting message, "Only local connections are allowed" even though browser launches properly
(note: my browser does not launch)
How do I run the test code as an executable?
Do I have to write additional code to invoke the test when running as executable?
Nuget Version Info
namespace RevuSeleniumAutomation
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.PhantomJS;
using System;
[TestClass]
public class RevuAutomater
{
private string baseURL = "http://example.com/";
private RemoteWebDriver driver;
private string browser;
public TestContext TestContext { get; set; }
[TestMethod]
[TestCategory("Selenium")]
[Priority(1)]
[Owner("Chrome")]
public void AutomateSite()
{
driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
driver.Navigate().GoToUrl(this.baseURL);
driver.FindElementById("UserName").SendKeys("user");
driver.FindElementById("Password").SendKeys("12345");
}
[TestCleanup()]
public void MyTestCleanup()
{
driver.Quit();
}
[TestInitialize()]
public void MyTestInitialize()
{
}
}
}
The cmd window message after launching exe
Thank you for your time.
To run as EXE I think there are two options:
1) not with selenium server or grid
. you need package the chromedriver.exe with your code into the EXE
. you code need to calculate the path of chromedriver.exe in runtime, because you don't know user will put the EXE in which folder
. specify chromedriver.exe by ChromeOptions to tell selenium where to find it when create driver instance
Shortage of this way: a chromedriver.exe of certian version support limited chrome verions, not all chrome verions, you need to tell user which chrome the EXE support.
2) use selenium server/grid
. you code need accept selenium server/grid address from a config file which user can modify it
. create RemoteWebDriver instance with above address, not ChromeDriver in code
. no need to package chromedriver.exe with your code
Shortage of this way: A selenium server/grid need be ready before execute EXE,
But your code no need to consider the compatibility of chrome and chromedriver.exe, because they had been considered when setup selenium server/grid.

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.