I am using the new Gecko Driver to test in Firefox. When I change the url it often fails. I have a test that goes to 10 different pages to perform a very basic health check. The pages always load when using Firefox manually (not Gecko/Selenium), but when using the Gecko driver it fails on the GoToUrl().
It's not consistent which of the ten pages it fails on, but it is always consistently failing on one of the ten. When it fails Firefox closes and an error message pops up asking if I want to submit the details to Mozilla.
Am I doing something wrong, or is there some restriction with the Gecko driver that I am unaware of? The Chrome and internet explorer drivers handle the exact same test just fine.
var service = FirefoxDriverService.CreateDefaultService(DriverPathOnSystem);
var driver = new FirefoxDriver(service);
driver.Navigate().GoToUrl(url);
EDIT
Selenium.Support v3.4.0 (nuget)
Selenium.WebDriver v3.4.0 (nuget)
Firefox 51.0.1 (32-bit) but also using the most recent version on the
build machine and it has the same failure there
Gecko 0.16.0
Upon further research I discovered I was actually using WebDriver v3.2.0.
I updated WebDriver to v3.4.0,
updated FireFox to 53.0.0,
updated GeckoDriver to 0.16.1
cleaned the solution and rebuilt and it worked.
Related
I want to load a new Selenium ChromeDriver that is using Chrome as if I open Chrome from my dock (Essentially it'll have all my extensions, history, etc.)
When I use the following code:
ChromeOptions options = new ChromeOptions();
options.AddArgument("user-data-dir=C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data\\");
options.AddArgument("disable-infobars");
options.AddArgument("--start-maximized");
ChromeDriver chromeDriver = new ChromeDriver(options);
It loads the Chrome browser with me signed into my Gmail and with all my extensions, just like I want, but the rest of my code:
chromeDriver.Navigate().GoToUrl("https://www.youtube.com/");
doesn't execute. But when I use the following
ChromeOptions options = new ChromeOptions();
options.AddArgument("user-data-dir=C:\\Users\\Andrea\\AppData\\Local\\Google\\Chrome\\User Data\\Default");
options.AddArgument("disable-infobars");
options.AddArgument("--start-maximized");
ChromeDriver chromeDriver = new ChromeDriver(options);
The rest of my code executes perfectly (Notice the 'Default' added to the end of the first Argument). Any tips or suggestions on how I can get the first block of code (The one without 'Default' on the end) to execute the rest of my program would be great. Thanks!
I know this is an old question, but what worked for me is to do remove the "C:\" and replace all of the backslashes with forward slashes. So, with that from the original question, this should work to load the default profile:
options.AddArgument("user-data-dir=/Users/User/AppData/Local/Google/Chrome/User Data");
The Default Chrome Profile which you use for your regular tasks may contain either/all of the following items:
History
Bookmarks
Cookies
Extensions
Themes
Customized Fonts
All these configurations untill and unless are part of your Test Specification it would be a overkill to load them into the session initiated by Selenium WebDriver. Hence it will be a better approach if you create a dedicated New Chrome Profile for your tests and configure it with all the required configuration.
Here you will find a detailed discussion on How to create and open a Chrome Profile
Once you have created the dedicated New Chrome Profile for your tests you can easily invoke the Chrome Profile as follows:
ChromeOptions options = new ChromeOptions();
options.AddArgument("user-data-dir=C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2");
options.AddArgument("disable-infobars");
options.AddArgument("--start-maximized");
ChromeDriver chromeDriver = new ChromeDriver(options);
chromeDriver.Navigate().GoToUrl("https://www.youtube.com/");
Here you will find a detailed discussion on How to open URL through default Chrome profile using Python Selenium Webdriver
I have the same issue. I don't know how to fix it, I guess the root cause is white space in profile path.
I know a workaround for this. Just copy the C:\\Users\\Andrea\\AppData\\Local\\Google\\Chrome\\User Data to c:\myUserData (no space in the path).
Then add the argument.
options.AddArgument("user-data-dir=C:\\myUserData");
This is an Old question, but if you are facing this issue, all you have to do is close all tabs, Just shut down the chrome window..
Selenium can't use the data since it is already in use.
Hope you fond this helpful.
I am facing getting The HTTP request to the remote WebDriver server for URL error while executing the selenium script in Chrome.
I am using Selenium with C# and Latest version of Chrome Driver, Chrome(66.0.3359.181) and Selenium(3.12.1)
Give this a try:- add the "no-sandbox" flag to the Chrome options:
var options = new ChromeOptions();
options.AddArgument("no-sandbox");
There are two causes to this exception I've seen:
1.Browser/web driver version mismatch - solved by updating webdriver nuget package to latest usually.
2.Server-side takes too long to load page - solved by either getting a faster server or as per https://code.google.com/p/selenium/issues/detail?id=5071 it looks like you can add a timeout argument when newing up a RemoteWebDriver, in Seleno that happens in Browser, but you don't have to use Browser you can new up the driver yourself to try out the fix. Feel free to submit a PR to Seleno to allow that timespan to be passed in as an option to the various drivers (probably in the override that has capabilities passed in).
Hope it helps!
Is it my understanding that when using Selenium.WebDriver v3.7 from NuGet I require a current version of geckodriver in order to interact with Firefox ESR v52.4.1. However, I have managed to get tests running and successfully passing without geckodriver being involved at all.
I believe it is because I have enabled the legacy implementation option when instantiating the RemoteWebDriver, as illustrated below.
FirefoxOptions options = new FirefoxOptions
{
UseLegacyImplementation = true, // means that geckodriver is not required
BrowserExecutableLocation = ..., // ensures authorised Firefox version used
Profile = ... // an instance of FirefoxProfile
};
RemoteWebDriver remoteWebDriver = new FirefoxDriver(options);
A number of questions to help me understand the details:
Does this mean that Selenium.WebDriver is talking directly to the Firefox browser using the Marionette protocol?
If so, does this setup rely on libraries currently distributed with the NuGet package that might be (will?) be dropped in a forthcoming release?
If so, any idea which release or when that is likely to be?
Thanks!
Does this mean that Selenium.WebDriver is talking directly to the Firefox browser using the Marionette protocol?
As per my understanding, when you set System.setProperty("webdriver.firefox.marionette", "false"); to false or do FirefoxOptions options = new FirefoxOptions()
.setLegacy(true); that means it is using the legacy extension (not marionette and gecko) as described in firefox properties here
Marionette can not be used without using gecko (or rather if you want to interact with gecko based browsers, you have to use marionette ). Marionette has a gecko component in it which is the marionette server as mentioned here
geckodriver as it is written on github , provides an API to communicate with Gecko browsers
This program provides the HTTP API described by the WebDriver protocol
to communicate with Gecko browsers
for selenium 3.0 onwards marionette is enabled by default as mentioned here
For more info please refer to this question also
If you are interested in learning more about marionette client-server-gecko interaction , have a look here
EDIT:
the source code of geckodriver states below points about geckodriver at different locations in readme.md
geckodriver is a Proxy for using W3C WebDriver-compatible clients to interact with
Gecko-based browsers.
Selenium client bindings will pick up the geckodriver binary executable
from your [system’s PATH environmental variable][PATH]
3.Since geckodriver is a separate HTTP server that is a complete
remote end
implementation of [WebDriver], it is possible to avoid using the
Selenium remote server
geckodriver translates WebDriver [commands], [responses],
and [errors] to the [Marionette protocol], and acts as a proxy between
[WebDriver] and [Marionette]
By default geckodriver tries to find
and use the system installation of Firefox
So , to answer your questions, this is how it all works
Selenium language bindings reaches to -->geckodriver.exe finds -->system firefox installation(this can be changed though)reaches to inbuilt --> marionette client reaches to --> marionette server reaches to --> gecko engine of the browser which inturn calls out --> element.js,interaction.js,action.js,evaluate.js in gecko engine depending on what is being requested by the bindings or client.
Currently, I'm trying to run my Selenium tests on Safari using Selenium Grid and RemoteWebDriver. This is my setup:
Mac OS Sierra 10.12.6 as a machine for running tests.
Selenium server 3.5.3.
Safari 11.
C# Selenium WebDriver and Selenium Support (latest version).
I'm using port forwarding on my host OS (Windows 10) to forward requests to Mac, running on my Virtual Machine. On my Mac I have Selenium Grid hub, which I run like this:
java -jar selenium-server-standalone-3.5.3.jar -role hub -port 4723
Also, there is a node:
java -jar selenium-server-standalone-3.5.3.jar -role node -hub http://10.0.2.15:4723/grid/register
In code, I start my driver like this:
SafariOprions options = new SafariOptions();
IWebDriver driver = new RemoteWebDriver(new Uri(hubURL), options.ToCapabilities());
My tests are running fine with current setup. But when it comes to clicking a link with attribute target='_blank' I'm starting to face some troubles. For other drivers, which I run locally, I can switch tab without any trouble: I'm getting driver.WindowHandles before I click a link, then I click a link and again retrieve Window Handles to compare with previous handles. After that I use driver.SwitchTo().Window(newHandle) and everything is ok.
But when it comes to RemoteWebDriver (or SafariDriver from Apple, I cannot say more precisely) I'm always getting only one Window Handle, even if the new tab is opened and i can see it.
I'm trying to avoid switching tab with "Command + T" as one of solutions suggested, because my tests are meant to be run on all browsers (Chrome, Firefox, Opera, Edge, Safari) and this wont work.
UPDATE: I've tried running Chrome and other browsers in Selenium Grid via RemoteWebDriver and I can say that this is not an issue of RemoteWebDriver. Next, I've installed Visual Studio for Mac and rewrite several things to run my tests without Selenium Grid, just using this code:
//if memory serves, just like this
SafariOptions options = new SafariOptions();
SafariDriver driver = new SafariDriver(options);
But, unfortunately, this didn't help. Driver navigated me to the page, clicked the link and opened a new tab, but without any switch. When I checked for driver.WindowHandles I've only got one, although there was two visible tabs. Neither driver.SwitchTo().ActiveElement nor driver.SwitchTo().Frame(hardcoded_frame_name) doesn't seem to work. Pretty long waits (for 60 seconds after opening the link and another one after that) aren't working too. Now I think that this is really a bug and I will try to report this to Apple as soon as I can.
But for now, maybe someone has a fancy workaround for this?
As we discussed in the comments, it seems to be a timing issue. So we will induce
WebDriverWait to sync up with the trailing Browser instance. I am providing a code block as a solution through Selenium-Java, consider implementing it in C# and update me if it works for you.
driver.get("http://www.google.com");
System.out.println("Page Title is : "+driver.getTitle());
String parent_window = driver.getWindowHandle();
((JavascriptExecutor) driver).executeScript("window.open('http://facebook.com/');");
WebDriverWait wait = new WebDriverWait(driver,3);
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
Set<String> allWindows_1 = driver.getWindowHandles();
ArrayList<String> tabs = new ArrayList<>(allWindows_1);
driver.switchTo().window(tabs.get(1));
wait.until(ExpectedConditions.titleContains("Facebook"));
System.out.println("First Child Handle : "+driver.getTitle());
I could help you with the Java version:
After the actions done, do this below.
//Store the parent window
String parentWindow = driver.getWindowHandle();
//Open a new Windows(Mailtrap)
String a = "window.open('https://mailtrap.io/signin','_blank');";
((JavascriptExecutor)driver).executeScript(a);
//This Thread.sleep is useful with Safari. Do not remove.
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//Take control over new browser
for(String handle: driver.getWindowHandles()){
driver.switchTo().window(handle);
}
I use Selenium WebDriver in my C# winforms application. When I run application and open Firefox, my addons are disabled. How to leave the addons enabled?
You can explicitly set the desired addons to ON. For example, if you want to enable firebug, find out the location of the zip or xpi of the addon and then use the following code:
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.AddExtension("C:\\firebug.xpi");
ffprofile.SetPreference("extensions.firebug.currentVersion", "1.11.4");
IWebDriver driver = new FirefoxDriver(ffprofile);
The only thing I did to resolve is just by adding following to the pom.xml and it worked fine for me. Currently I'm running tests on Firefox 43.0.3 with Selenium 2.48.2. and also by have a dependency for the Firefox browser in the pom.xml.
org.seleniumhq.selenium selenium-firefox-driver 2.48.2
org.seleniumhq.selenium selenium-java 2.48.2
After using this if you fail to use your add on than drop message I will provide you some more options but hope fully you will get result from this.