It shows error after using geck V0.16.1 - selenium

It shows error after using geckodriver V0.16.1 Browser is getting opened and also URL is opened, but shows below error while opening browser:
1496729301597 geckodriver INFO Listening on 127.0.0.1:26189
1496729302267 geckodriver::marionette INFO Starting browser
\?\C:\Program Files\Mozilla Firefox\firefox.exe with args
["-marionette"]
1496729302562 addons.manager ERROR startup failed: [ExceptioJavaScript
error: resource://gre/modules/AddonManager.jsm, line 1657:
NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
n... "Component returned failure code: 0x80070057
(NS_ERROR_ILLEGAL_VALUE) [nsIFile.create]" nsresult: "0x80070057
(NS_ERROR_ILLEGAL_VALUE)" location: "JS frame ::
resource://gre/modules/FileUtils.jsm :: FileUtils_getDir :: line 70"
data: no] Stack trace:
FileUtils_getDir()#resource://gre/modules/FileUtils.jsm:70 <
FileUtils_getFile()#resource://gre/modules/FileUtils.jsm:42 <
validateBlocklist()#resource://gre/modules/AddonManager.jsm:671 <
startup()#resource://gre/modules/AddonManager.jsm:834 <
startup()#resource://gre/modules/AddonManager.jsm:3129 <
observe()#resource://gre/components/addonManager.js:65
JavaScript error: resource://gre/components/SanityTest.js, line 65:
NS_ERROR_FILE_ACCESS_DENIED: Component returned failure code:
0x80520015 (NS_ERROR_FILE_ACCESS_DENIED) [nsIPrefService.savePrefFile]
JavaScript error: resource://gre/modules/AddonManager.jsm, line 2570:
NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
1496729310139 Marionette INFO Listening on port 50194
Jun 06, 2017 11:38:30 AM org.openqa.selenium.remote.ProtocolHandshake
createSession
INFO: Detected dialect: W3C
My code is as given below:
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
WebDriver driver ;
System.setProperty("webdriver.gecko.driver","D:\\geckodriver-v0.16.1-win64\\geckodriver.exe");
driver = new FirefoxDriver();
driver.get("http://google.co.in");
}

May I know which selenium standalone server version you are using? It should work fine with 3.4.0

Related

pageLoadTimeout is not working in Selenium - Java

I am testing a website in linux host.The page i am accessing loads infinitely so I am trying to set pageLoadTimeout for selenium.
Firefox is triggered correctly but URL is not loading/navigating/added in url bar.just blank firefox window.I am not seeing any errors also.
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS);
driver.get("http://www.example.com");
However if I remove driver.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS); code is working fine
Selenium version : 3.14.0;
gecko driver : 18 - linux (tested with gecko 16,17 also same issue)
browser : firefox-52
os/platform : linux
If this kind of some issue how do I make sure my driver quit itself after 5 minute.Host will support only firefox 52.
I checked this link but doesnt fix my problem.
Thanks
Jk
You can set the pageload strategy for browser which will then make the page not wait for the full page load for your other Selenium commands to be executed. Below is the sample code snippet in Java. There are three supported values:
normal
This stategy causes Selenium to wait for the full page loading (html content and subresources downloaded and parsed).
eager
This stategy causes Selenium to wait for the DOMContentLoaded event (html content downloaded and parsed only).
none
This strategy causes Selenium to return immediately after the initial page content is fully received (html content downloaded).
By default, when Selenium loads a page, it follows the normal pageLoadStrategy.
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("pageLoadStrategy", "eager");
FirefoxOptions opt = new FirefoxOptions();
opt.merge(caps);
WebDriver driver = new FirefoxDriver(opt);
driver.get("https://www.google.com/");
If you are interested only in the HTML of the page, better use the "eager" strategy.
You haven't mentioned the url you are trying to access but pageLoadTimeout for Selenium works as expected with With Selenium v3.14.0, GeckoDriver v0.23.0 and Firefox Quantum v62.0.3 combination. I am able to see the expected output on the console with the following example which prints TimeoutException occurred. Quiting the program whenever the pageLoadTimeout is triggered:
Code Block:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class A_Firefox_Test
{
public static void main(String[] args)
{
System.setProperty("god.bless.us", "C:/Utility/BrowserDrivers/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS);
try {
driver.get("https://www.booking.com/hotel/in/the-taj-mahal-palace-tower.html?label=gen173nr-1FCAEoggJCAlhYSDNiBW5vcmVmaGyIAQGYATG4AQbIAQzYAQHoAQH4AQKSAgF5qAID;sid=338ad58d8e83c71e6aa78c67a2996616;dest_id=-2092174;dest_type=city;dist=0;group_adults=2;hip_dst=1;hpos=1;room1=A%2CA;sb_price_type=total;srfid=ccd41231d2f37b82d695970f081412152a59586aX1;srpvid=c71751e539ea01ce;type=total;ucfs=1&#hotelTmpl");
} catch (TimeoutException e) {
System.out.println("TimeoutException occurred. Quiting the program.");
}
driver.quit();
}
}
Console Output:
1539157195615 Marionette INFO Listening on port 1920
Oct 10, 2018 1:09:56 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Oct 10, 2018 1:10:00 PM org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: '500' -> incorrect JSON status mapping for 'timeout' (408 expected)
TimeoutException occurred. Quiting the program.
You can find the detailed stack trace in pageLoadTimeout in Selenium not working
You can find the Pythonic approach to pageLoadTimeout in How to set the timeout of 'driver.get' for python selenium 3.8.0?

Exception in thread "main" org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary using webdriver.firefox.marionette

public class TestClass1 {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://accounts.google.com/signin");
driver.close();
System.exit(0);
}
}
This code is results in the following:
Exception in thread "main" org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe) on port 7055; process output follows:
[
{
"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
"minVersion":"63.0","maxVersion":"63.*"
}
],
"targetPlatforms":[],
"seen":true,
"dependencies":[],
"hasEmbeddedWebExtension":false,
"userPermissions":null,
"icons":{},
"blocklistState":0,
"blocklistURL":null,
"startupData":null,
"hidden":true,
"location":"app-system-defaults"
}
Try this out:
Make sure that your FF version is 63 (the latest on Oct 30, 2018)
Make sure your selenium version is 3.14
Make sure that you have downloaded latest geckodriver 0.23 (https://github.com/mozilla/geckodriver/releases)
Make sure geckodriver.exe is in the root of C:\\ (or change the path below)
Use: System.setProperty("webdriver.gecko.driver", "C:\\geckodriver.exe");
If it does not work, try downgrading your FF to a previous 62 version and give it a try.
FYI read this Difference between webdriver.firefox.marionette & webdriver.gecko.driver
Supported versions:
https://firefox-source-docs.mozilla.org/testing/geckodriver/geckodriver/Support.html
While working with Selenium 3.x, GeckoDriver and Firefox you need to download the latest required version of GeckoDriver from mozilla/geckodriver, extract it and mention the absolute path of the GeckoDriver binary through System.setProperty() line through the Key webdriver.gecko.driver instead of webdriver.firefox.marionette as follows:
public class TestClass1 {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:\\path\\to\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://accounts.google.com/signin");
driver.quit();
}
}
Note: Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
Supported Platforms
The following table shows a mapping between geckodriver releases, supported versions of Firefox, and required Selenium version:

Selenium Chrome Browser org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start

public class Dem {
public static void main(String[] args) throws InterruptedException {
WebDriver driver;
String url = "https://www.google.com";
System.setProperty("webdriver.chrome.driver","C:\\Users\\Jim\\Downloads\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.get(url);
driver.close();
}
}
Selenium webdriver and Chrome driver are the latest versions
Selenium webdriver :3.14.0
chromedriver: 2.42
java:1.8.0_181
And this is the error after running the code. Google chrome doesn't launch at all.
SEVERE: org.apache.commons.exec.ExecuteException: Process exited with an error: -1073741792 (Exit value: -1073741792) Exception in
thread "main" org.openqa.selenium.WebDriverException: Timed out
waiting for driver server to start. Build info: version: '3.14.0',
revision: 'aacccce0', time: '2018-08-02T20:13:22.693Z' Driver info:
driver.version: ChromeDriver at
org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:193)
at
org.openqa.selenium.remote.service.DriverService.start(DriverService.java:179)
at
org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at
org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:212)
at
org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:130)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:181)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:168)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123)
at news.Dem.main(Dem.java:17) Caused by:
org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting
for [http://localhost:32986/status] to be available after 20002 ms at
org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
at
org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:188)
... 9 more
Debugging Steps
It may be either of the two below issue.
1. Chrome Driver not started for some reason:
Run the chrome driver in terminal maually
C:\Users\Jim> C:\Users\Jim\Downloads\chromedriver_win32\chromedriver.exe
Now we have to get the following message denoting server started sucessfully.
If you are not getting above message and your server is not started, then check what is error you are getting and respond accorsingly? May downloaded corrupted binary, the download it again.
2. Unable to access the chrome driver with hostname as localhost
If you able to start chromedriver sucessfully as in above steps, now try to access the below url with respective port.
http://localhost:{port}/status
For e.g., in above message, the server started on port 9515. Access the url in browser, http://localhost:9515/status
You should get above message indicating server is accessible with hostname as localhost
If your are not able access, then open C:\Windows\System32\drivers\etc\hosts in editor with administrator privilege and check localhost DNS is mapped to 127.0.0.1
public class Demo {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","\PATH OF THE DRIVER");
WebDriver driver = new Chrome driver();
String url = "https://www.google.com";
driver.get(url);
Thread.sleep(2000);
driver.close();
}
}

Unable to run selenium web driver project for 3.8.1 version

Unable to run web driver 3.8.1 geckodriver 0.19.1 with guava 21 and 22 .
Firefox version 58.0.2 (64-bit)
getting error as :
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
running on iMac
System.setProperty("webdriver.gecko.driver", "//Users//(username)//Downloads//engage-test//engage-test-common//exes//geckodriver");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver= new FirefoxDriver(capabilities);
The error says it all :
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
Class NoSuchMethodError
public class NoSuchMethodError extends IncompatibleClassChangeError and as per the Java Docs it is thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method. Normally, this error is caught by the compiler and this error can only occur at run time if the definition of a class has incompatibly changed.
Solution
Perform the following steps :
When providing absolute paths either use double back slashes (\\) or single front slashes (/). Both are equivalent. So you need to update the System.setProperty() as follows :
System.setProperty("webdriver.gecko.driver", "/Users/<username>/Downloads/engage-test/engage-test-common/exes/geckodriver"); //Linux Style
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
Update your JDK to the most recent versions JDK 8u161
Upgrade Selenium-Java Clients to v3.10.0.
Clean up the Project Space from your IDE.
Run CCleaner tool to wipe off all the OS system chores.
If your base Web Browser version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of the Web Browser.
Take a System Reboot.
Execute your #Test
Update
As you are using Selenium-Java Client 3.11.0 where support of DesiredCapabilities is deprecated from the list of constructors for FirefoxDriver Class you have to use the method merge(Capabilities extraCapabilities) and merge the capabilities into an FirefoxOptions Class object as follows :
package demo;
import java.util.logging.Level;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class A_Firefox_DC_Opt
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("marionatte", true);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
FirefoxDriver driver = new FirefoxDriver(opt);
driver.get("https://stackoverflow.com");
System.out.println("Application opened");
System.out.println("Page Title is : "+driver.getTitle());
driver.quit();
}
}
Console Output :
1522037759633 geckodriver INFO geckodriver 0.20.0
1522037759653 geckodriver INFO Listening on 127.0.0.1:20073
1522037760415 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\ATECHM~1\\AppData\\Local\\Temp\\rust_mozprofile.hRnaFvWiVBua"
1522037762202 Marionette INFO Enabled via --marionette
1522037765376 Marionette INFO Listening on port 1176
1522037765636 Marionette WARN TLS certificate errors will be ignored for this session
Mar 26, 2018 9:46:05 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Application opened
Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers

Selenium 3.0.1 crashes FireFox 51.0.1 during driver.quit() # Win 7 Home Premium & GeckoDriver 0.13.0

Win 7 and FireFox is running in German language.
Win 7 has all available updates installed.
Same for 32 and 64 Bit GeckoDriver! (my Win 7 ist 64 Bit; my FireFox is 32 Bit).
Same for GeckoDriver 0.14.
Is this just a problem on my PC ?
driver.quit() is working on my InternetExplorer without a problem.
package JS_JFrame1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SeleniumFireFoxMinimal1 {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "e:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.toolsqa.com");
Thread.sleep(5000);
driver.quit();
}
}
Other selenium commands like these work perfectly well:
element = driver.findElement(By.id("sinp"));
System.out.println( "Element found!");
element.clear();
element.sendKeys("black");
element.submit();
Eclipse Console-Output:
1485978825934 geckodriver INFO Listening on 127.0.0.1:21352 Feb 01,
2017 8:53:46 PM org.openqa.selenium.remote.ProtocolHandshake
createSession INFORMATION: Attempting bi-dialect session, assuming
Postel's Law holds true on the remote end
1485978826606 mozprofile::profile INFO Using profile path
C:\Users\xxxxxxx\AppData\Local\Temp\rust_mozprofile.qNYZq4KKbeGl
1485978826606 geckodriver::marionette INFO Starting browser C:\Program
Files (x86)\Mozilla Firefox\firefox.exe
1485978826637 geckodriver::marionette INFO Connecting to Marionette on
localhost:51926 1485978828021 Marionette INFO Listening on port 51926
Feb 01, 2017 8:53:52 PM org.openqa.selenium.remote.ProtocolHandshake
createSession INFORMATION: Detected dialect: W3C JavaScript warning:
https://www.youtube.com/yts/jsbin/player-de_DE-vflWB2cvt/base.js, line
664: Error: WebGL: getParameter: parameter: invalid enum value [Child 4416] ###!!! ABORT: Aborting on channel error.: file
c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/glue/MessageChannel.cpp,
line 2056 Feb 01, 2017 8:54:07 PM org.openqa.selenium.os.UnixProcess
destroy SCHWERWIEGEND: Unable to kill process with PID 4608
set browser.tabs.remote.autostart.2 to false.
FirefoxOptions options = new FirefoxOptions();
options.BrowserExecutableLocation = Settings.Default.FirefoxBinary;
>>>> profile.SetPreference("browser.tabs.remote.autostart.2", false);
FirefoxProfile profile = new FirefoxProfile();
....
options.Profile = profile;
driverSet.Driver = new FirefoxDriver(options);
The issue is related to the fact firefox started using multiprocess environment from firefox version >= 50, and it seems selenium is unable to handle it.
Adding the following lines should resolve this issue :
FirefoxProfile ffProfile = new FirefoxProfile();
ffProfile.setPreference("browser.tabs.remote.autostart.2", false);
WebDriver driver = new FirefoxDriver(newFirefoxOptions().setProfile(ffProfile));
It's a known Firefox/geckodriver issue with quitting driver, see here for more details.
It appears in some FF versions, some say it's fixed, some say it's not. I couldn't find better solution for this so I switched on 'old' Firefoxdriver and FF v47.0.2 which works fine.
I found a workaround for this. My code is in C#
Utility.Instance.KillProcess("firefox");
System.Windows.Forms.SendKeys.SendWait("{ESC}");
Utility.Instance.KillProcess("geckodriverserver");
Hope it will help you.