Recently we upgraded our Selenium C# binding , v3.4 and we are start using the Gecko Driver which is for FF support, so we are using v 0.16.1,
We notice that after click that open new window (FF) we got WebDriverException handlers time out, pops from : driver.WindowHandles (Selenium command),
We are wondering if it is common issue or if you know how to workaround that issue?
Init Driver Code:
public void Setup()
{
var driverService = FirefoxDriverService.CreateDefaultService();
driverService.FirefoxBinaryPath = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
driverService.HideCommandPromptWindow = true;
driverService.SuppressInitialDiagnosticInformation = true;
m_driver = new FirefoxDriver(driverService, new FirefoxOptions(), TimeSpan.FromSeconds(60));
}
As per the documentation here to work with geckodriver v0.16.0 you need to bump up your Selenium version to 3.4.0. So it essentially means to work with geckodriver v0.16.1 Selenium 3.4.0 is mandatory.
Note that geckodriver v0.16.0 is only compatible with Selenium 3.4 and greater.
Related
if i open Chrome via chromedriver and navigate to a URL i only get a data:, in the navigation bar. All googled solutions (right chromedriverversion, protocoll in URL, etc.) didnt help me.
package de.vhv.selenium;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class OpenChromeAndNavigate {
#Test
public void test() {
System.setProperty("webdriver.chrome.driver", "C://vhventw//selenium//chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.de");
}
}
In addition everything works if i add --headless and listen to the debugport. But i dont want to let it run headless.
package de.vhv.selenium;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class OpenChromeAndNavigate {
#Test
public void test() {
System.setProperty("webdriver.chrome.driver", "C://vhventw//selenium//chromedriver.exe");
WebDriver driver = new ChromeDriver(getDesiredCapabilities());
driver.get("https://www.google.de");
}
private ChromeOptions getDesiredCapabilities() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
// options.addArguments("--disable-extensions"); // disabling extensions
// options.addArguments("--disable-gpu"); // applicable to windows os only
// options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
// options.addArguments("--no-sandbox");
options.addArguments("--remote-debugging-port=9223");
return options;
}
}
Any ideas what i can try?
Setup:
Chrome Version = 71.0.3578.80
Chromedriver Version = 2.46.628402
I figured out, that the line
options.addArguments("--remote-debugging-port=9225");
fixed my problem. I already used it in headless runs to listen to the port and watch the headless run. But it fixed my problem with headfull runs.
return new ChromeDriver(getDesiredCapabilities());
private ChromeOptions getDesiredCapabilities() {
ChromeOptions options = new ChromeOptions();
//options.addArguments("--headless");
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--no-sandbox");
options.addArguments("--remote-debugging-port=9225");
return options;
}
You need to take care of a couple of things:
Not sure about your project structure but I will suggest to avoid the . character and the word selenium within the package name as in:
package de.vhv.selenium;
The Value part passed through System.setProperty() line containing the absolute path of chromedriver.exe should be expressed through escaped backslashes as:
System.setProperty("webdriver.chrome.driver", "C:\\vhventw\\selenium\\chromedriver.exe");
As per ChromeDriver - WebDriver for Chrome:
If you are using Chrome version 72, please download ChromeDriver 2.46 or ChromeDriver 72.0.3626.69
As per best practices:
Upgrade JDK to recent levels JDK 8u202.
Upgrade Selenium to current levels Version 3.141.59.
Upgrade ChromeDriver to current ChromeDriver v73.0.3683.68 level.
Keep Chrome version between Chrome v73 levels. (as per ChromeDriver v73.0.3683.68 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
I was struggling with the same issue, then I realised that I forgot to start the test with :
$I->amOnPage('/');
definitely to try before digging deeper.
I'm writing integration/e2e tests and for some reason any selenium driver commands don't see to be working with chromedriver, but they are working flawlessly with firefox driver and the firefox headless driver.
Commands tried: moveByOffset, and doubleClick
Tried both Geb's Interact method
interact {
doubleClick(centerClickable)
}
and accessing the webdriver directly:
def driver = browser.getDriver()
Actions action = new Actions(driver)
WebElement element= driver.findElement(By.className("vis-drag-center"))
def doubleclick = action.doubleClick(element).build()
doubleclick.perform()
Both methods work with the firefox driver. Neither work with chrome driver.
GebConfig.groovy file is set up as thus:
import io.github.bonigarcia.wdm.WebDriverManager
import org.openqa.selenium.Dimension
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions
def chromeWebDriverVersion = '70.0.3538.67'
def driverFirefox = {
WebDriverManager.firefoxdriver().setup()
def driver = new FirefoxDriver()
driver.manage().window().setSize(new Dimension(width, height))
return driver
}
// ChromeDriver reference: https://sites.google.com/a/chromium.org/chromedriver/
// Download and configure ChromeDriver using https://github.com/bonigarcia/webdrivermanager
def driverChrome = {
WebDriverManager.chromedriver().version(chromeWebDriverVersion).setup()
def driver = new ChromeDriver()
driver.manage().window().setSize(new Dimension(width, height))
return driver
}
environments {
firefox {
driver = driverFirefox
}
chrome {
driver = driverChrome
}
//driver = driverFirefox
driver = driverChrome
I also tried version 2.43 of chrome.
Additional information:
Mac Mojave
Selenium v 3.7.0
geb v 2.2
spockcore v 1.1-groovy-2.4
groovy v 2.4.5
webdrivermanager v 3.0.0
If anyone is interested, what the test is doing: Selecting a vis.js element by clicking on it. Sleeping for a second (code not included here), then opening/activating it by double clicking it. Or dragging it.
Apart from the selenium actions everything works fine with chromedriver and geb. It's only now that I need the doubleClick and moveByOffset (not move to an element!) that I'm getting issues getting things to work properly
I found a similar question on here, might be the same issue. Maybe not. But there's no solution provided: Selenium Web Driver DragAndDropToOffset in Chrome not working?
Any help is hugely appreciated.
Thank you for your response kriegaex.
Your tests work for me as well. This leads me to think there's just some lower-level interaction between differences in how selenium's chromedriver and firefox driver have implemented the doubleclick and dragAndDropBy actions + the way our application responds to commands.
For any other people observing similar behaviour, I use a work-around where I add an additional action for chromedriver. Perhaps it's nicer to actually find out which KEYDOWN events etc. you should be using and fire those, or perhaps find out why application isn't responding to these events. But I feel like enough time is spent on this already :)
if (browser.getDriver().toString().contains("chrome")) {
// Work-around for chromedriver's double-click implementation
content.click()
}
interact {
doubleClick(content)
}
And for the dragAndDropBy:
def drag(Navigator content, int xOff, int yOff) {
//Work-around: move additional time for when chrome driver is used.
int timesToMove = browser.getDriver().toString().contains("chrome") ? 2 : 1
interact {
clickAndHold(content)
timesToMove.times {
moveByOffset(xOff, yOff)
}
release()
}
}
I just had a little bit of time and was curious because I never tried to perform a double-click in any of my tests before. So I used this page as a test case and ran the following test with both Firefox and Chrome drivers:
package de.scrum_master.stackoverflow
import geb.spock.GebReportingSpec
import org.openqa.selenium.By
import org.openqa.selenium.interactions.Actions
class DoubleClickTest extends GebReportingSpec {
def "double-click via Geb interaction"() {
given:
go "https://demo.guru99.com/test/simple_context_menu.html"
def doubleClickButton = $("button", text: "Double-Click Me To See Alert")
expect:
withAlert {
interact {
doubleClick(doubleClickButton)
}
} == "You double clicked me.. Thank You.."
}
def "double-click via Selenium action"() {
given:
go "https://demo.guru99.com/test/simple_context_menu.html"
def doubleClickButton = driver.findElement(By.tagName("button"))
def doubleClick = new Actions(driver).doubleClick(doubleClickButton).build()
expect:
withAlert {
doubleClick.perform()
} == "You double clicked me.. Thank You.."
}
}
It works flawlessly, both ways of double-clicking trigger the expected Javascript alert.
I am not even using the latest driver version 2.45 but 2.41 against Chrome 71 64-bit on Windows 10. Besides, I also use bonigarcia's Webdriver Manager. I have no idea what is wrong with your setup. My Selenium version is 3.14.0, a bit newer than yours, Geb 2.2, Spock 1.1-groovy-2.4, Groovy 2.4.7.
Maybe it is a MacOS thing? I cannot verify that. Maybe you just run my test first, then maybe upgrade your Selenium and if that also does not help try to downgrade the Chrome driver in order to find out if the problem could be driver version related.
Update: I upgraded to Chrome driver 2.45, the test still works.
Update 2022-02-16: Updated the test to work with another example page, because the old URL still exists, but the Javascript there no longer works.
It is known issue that, Firefox version 47.0.1 is not compatible with Selenium latest version. Even Firefox is announcing to use Marionette instead. Can someone give some details instruction on how to use Marionette with Geb?
As a maven project, I tried all the version of Selenium with Geb but could not be successfull. I tried the following versions;
2.50.0
2.50.1
2.51.0
2.52.0
2.53.0
2.53.1
2.6.0
2.7.0
2.8.0
2.9.0
If this is not the right place to ask this, please guide me.
I have the next configuration in GebConfig.groovy:
firefox {
System.setProperty("webdriver.gecko.driver","path/geckodriver")
driver = {new MarionetteDriver()}
}
I am using selenium 3.0.1 and I using the -Dgeb.env=firefox system property in order to make sure it takes my Firefox configuration and it working fine for me
Regards
Download the latest version of selenium standard version 2.53.1 from selenium.hq.org.downloads and try to use the newest version of the Firefox.
With version 48 of Firefox, it looks like the only solution is using marionnette, however I have not been able to get this to work in Geb yet.
This is what I have tried in GebConfig.groovy:
environments {
firefox {
driver = {
DesiredCapabilities dc = DesiredCapabilities.firefox();
LoggingPreferences prefs = new LoggingPreferences();
prefs.enable(LogType.BROWSER, Level.WARNING);
dc.setCapability(CapabilityType.LOGGING_PREFS, prefs);
dc.setCapability("marionette", true);
String currentDir = System.getProperty("user.dir");
String marionetteDriverLocation = currentDir + "/WebDriver/wires";
System.setProperty("webdriver.gecko.driver", marionetteDriverLocation);
FirefoxProfile p = new FirefoxProfile();
p.setPreference("webdriver.gecko.driver", marionetteDriverLocation);
p.setPreference("webdriver.log.file", "/tmp/firefox_console");
p.setPreference("toolkit.telemetry.enabled", false);
p.setPreference("geo.enabled", false);
p.setPreference("plugins.update.notifyUser", false);
p.setPreference("datareporting.healthreport.service.enabled", false);
p.setPreference("datareporting.healthreport.uploadEnabled", false);
p.setPreference("datareporting.policy.dataSubmissionEnabled",false);
p.setPreference("datareporting.healthreport.service.firstRun", false);
p.setPreference("datareporting.healthreport.logging.consoleEnabled", false);
p.setPreference("reader.parse-on-load.enabled", false);
dc.setCapability(FirefoxDriver.PROFILE, p);
def driver = new FirefoxDriver(dc)
driver.manage().timeouts().pageLoadTimeout(45, TimeUnit.SECONDS)
return driver
}
It should work with any of the late Selenium versions. (everything > 2.50 not sure for earlier versions)
Marionette is an external driver, it's not included in the Selenium packages (yet?)
You need to Download the gecko driver here https://github.com/mozilla/geckodriver/releases
then point selenium to the location of the geckodriver.exe
You can do that as Nelson said before in GebConfig with:
import org.openqa.selenium.firefox.MarionetteDriver
driver = {
System.setProperty("webdriver.gecko.driver","path/geckodriver")
new MarionetteDriver()
}
to make that work you will need some dependencies in your buildscript, I'm working with gradle, yours might look different, just look into what yours need to look like on maven central
compile('info.novatec.testit:webtester-support-marionette:2.0.4') { transitive = false }
compile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
compile "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
(selenium support might not be necessary for you)
If you need more help, a more specific description of where you are failing would be helpful, you can also look here for a working project (with maven):
http://seleniumsimplified.com/2016/04/how-to-use-the-firefox-marionette-driver/
public class Driver {
public FirefoxDriver getFirefoxDriver(){
System.setProperty("webdriver.gecko.driver", "./geckodriver.exe");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
return new FirefoxDriver(options);
}
}
Could someone please help me with the following issue.
While I'm trying to initialize a browser I get the 'os error' exception.
var option = new FirefoxOptions();
option.IsMarionette = true;
var driver = new FirefoxDriver(option);
var b = new Browser(driver); // Throws an exception with a message - 'os error'
The screenshot of the exception
Plese note, the path to wires.exe is added to the system PATH. Selenium, wires, firefox are of the latest versions. I have tried running using firefox-stable and firefox-developer editions.
Thanks.
So I ran into the 'os error' issue when I was trying to get Marionette working. The source of the issue in my case was I was trying to use some NuGet package called 'Mozilla Firefox Webdriver 0.6.0.1' which I believe had a very old version of the (now called) geckodriver.exe.
I downloaded the latest version of the driver from here https://github.com/mozilla/geckodriver/releases
renamed to wires.exe and put in my working directory
then I had to initiate the driver using the following code.
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
service.FirefoxBinaryPath = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
Driver = new FirefoxDriver(service);
The way you initated the driver was giving me an entity not found exception.
Hope this helps
Maybe DesiredCapabilities would work.
DesiredCapabilities capabilities = DesiredCapabilities.Firefox();
capabilities.SetCapability("marionette", true);
var driver = new FirefoxDriver(capabilities);
When I create the Augmenter (see below) with 2.25 release of Selenium, it used to work fine. With 2.26 and 2.27 I'm getting the following error. Could you please suggest what extra is needed with a 2.26+ release to get things working again?
I get the following error:
java.lang.IllegalAccessException-->Class org.openqa.selenium.remote.Augmenter$CompoundHandler can not access a member of class org.openqa.selenium.firefox.FirefoxDriver with modifiers "protected"Exception caught starting Firefox webdriver
The relevant code:
WebDriver driver = new FirefoxDriver();
WebDriver augmentedDriver = new Augmenter().augment(driver);
Since newer release of selenium Agumenter only works for the RemoteWebDriver.
It was never really supported, but now is also doesn't work
Which feature you need the Agumenter for?
I.e. to take a screenshot you can make make a direct cast of the FriefoxDriver:
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
To initialize a mixed hub/local driver:
if (useHub) {
...
webDriver = new RemoteWebDriver(hubURL, desiredCapabilities);
webDriver = new Augmenter().augment(webDriver);
} else {
switch(webDriverType) {
case Type.FIREFOX:
webDriver = new FirefoxDriver();
}
}
then use webDriver as normal