I am using selenium chrome driver with version 3.6.0
and using google-guava 23.0.
When i do this :
ChromeOptions chromeOptions = new ChromeOptions();
It gives following error :
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157)
I also checked this : https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver/3.6.0
Can anyone help me what version of guava should i use here ?
Code :
System.setProperty("webdriver.chrome.driver", driverPath);
log.warn("chrome driver path is : {}", driverPath);
List<String> options = proxyConfig.getChromeOptions();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments(options);
Map<String, String> capabilites = proxyConfig.getCapabilities();
for(Map.Entry<String, String> entry : capabilites.entrySet()) {
chromeOptions.setCapability(entry.getKey(), entry.getValue());
}
return new ChromeDriver(chromeOptions);
It is not clear from your question about your particular usecase why you are trying to signal out Selenium Client v 3.6.0 and google-guava 23.0 individually.
To keep it simple,
Selenium Client v 3.6.0 uses guava v23.0
Release Notes of Selenium Client v 3.5.1 clearly mentions the following :
Bump guava to version 23.
So, I don't see any issue out there.
However, as an end user instead of selecting individual jars from multiple selenium-java-X.Y.Z.zip releases user should consider completely removing all the Selenium related jars from the older build and replace with the new jars from the new build.
This particular issue
This error message...
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
...implies that the Java Client was unable to find ChromeDriver()
It will be tough to analyze the real issue in absence of your code trials. However as per java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;) with Selenium, gradle and ChromeDriver you need to use the System.setProperty() line to set the ChromeDriver binary path (not the chrome binary path). For that you have to download the ChromeDriver binary from the ChromeDriver - WebDriver for Chrome and place it in your system and mention the absolute path of the ChromeDriver through System.setProperty() line. Hence you have to use the line :
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
// configurations through chromeOptions
WebDriver driver = new ChromeDriver(chromeOptions );
Related
I try to run electron app using the following code:
#Test
public void testElectron() {
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary(this.electronPath);
WebDriver driver = new ChromeDriver(chromeOptions);
}
But I get the following error:
Starting ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280#{#1761}) on port 37592
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
org.openqa.selenium.SessionNotCreatedException: session not created: This
version of ChromeDriver only supports Chrome version 87
Current browser version is 80.0.3987.165 with binary path src\main\resources\electron\electronApp.exe
Is there a specific chromedriver the is suitable for electron app (for selenium java)?
This error message...
Current browser version is 80.0.3987.165 with binary path src\main\resources\electron\electronApp.exe
...implies that the Chrome browser version is 80.0.
Solution
So as a solution you have to download the matching ChromeDriver
from ChromeDriver v80.0.3987.106 repository.
Selenium: 3.141.59;
Chromium Edge: Version 87.0.664.41 (Official build) (64-bit);
hub runs on linux, nodes on Windows 10.
I Would like to set up the RemoteWebDriver with Chromium Edge version 87. I have tried various options, and I am currently most successful with:
ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
EdgeOptions edgeOptions = new EdgeOptions().merge(options);
RemoteWebDriver drv = new RemoteWebDriver(new URL(globalSetting.getHubUrl()),
edgeOptions);
drv.get("http://www.google.com");
With this the edge browser starts, but is unable to connect to the google url, because it is stuck in RemoteDriver setup. After some time, I get the a timeout and the message: WebDriverException: unknown error: unrecognized Chrome version: Edg/87.0.664.41
[With Chrome (google) it works fine.]
I red somewhere that this merge is not working with newer Chromium Edge and EdgeOptions should be used instead. But I only found Python code and it uses a field which EdgeOption in Java does not have (options.useChromium = true).
Has anybody been successful with Chromium Edge 86/87 and RemoteWebDriver in Java? If so could you provide a code example?
Chrome is not stable on my Jenkins. When I run build 5 times, it runs 1 - 2-time success, and the other 3 times I have the above error.
Snapshot of the error:
Code for Chrome :
ChromeOptions options = new ChromeOptions();
System.setProperty("webdriver.chrome.driver","/usr/local/bin/chromedriver");
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
driver = new ChromeDriver(options);
driver.get("https://mywebsite.com");
Some steps I have already taken :
Provided 777 permission to google chrome and chrome driver
Set : Start Xvfb before the build, and shut it down after to True in Jenkins build setting
ChromeDriver 81.0.4044.69
Google Chrome 81.0.4044.129
Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-99-generic x86_64)
This error message...
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Deep dive
Looking into the snapshot of the error stacktrace you have provided, though you mentioned about using ChromeDriver 81.0.4044.69 and Google Chrome 81.0.4044.129, still it appears there is a mismatch between the versions of the different binaries you are using, possibly Chrome browser is not installed at the default location within your system or due to JDK mismatch. Additionally, ChromeDriver 81.0.4044.69 (2020-03-17) was a bit unstable which was replaced by ChromeDriver 81.0.4044.138 (2020-05-05)
However, the server i.e. ChromeDriver expects you to have Chrome installed in the default location for each system as per the image below:
1For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.
You can find a detailed discussion in What is default location of ChromeDriver and for installing Chrome on Windows
Solution
In case you are using the Chrome executable in a non-standard location you have to override the Chrome binary location as follows:
Code based solution:
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
ChromeOptions options = new ChromeOptions();
options.setBinary('/usr/bin/google-chrome'); //chrome binary location
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com/");
//execute the remaining steps
driver.quit();
Additional considerations- Ensure the following:
JDK is upgraded to current levels JDK 8u251.
Selenium is upgraded to current levels Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v81.0.4044.138 level.
Chrome is updated to current Chrome Version 81.0.4044.138 level. (as per ChromeDriver v80.0 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
References
You can find a couple of relevant discussions in:
WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium?
Running Chromedriver on Ubuntu Server headlessly
Okay so I am learning Web Scraping and am comfortable with Java hence I choose Jsoup, which is a web scraping library. I planned on scraping A CodeChef contest problem (which is just a coding problem), but I found difficulty scraping all the displayed content, which is not possible as most of it is dynamic source. So I used selenium to render the JavaScript and obtain simple HTML page and then feed it to JSOUP.
So I tried printing the rendered HTML page just to verify, but I get the following error when I run the code:
My Code:
File f = new File("<Path to chromedriver.exe>");
System.setProperty("webdriver.chrome.driver", f.getAbsolutePath());
WebDriver driver = new ChromeDriver();
driver.get("https://www.codechef.com/problems/FRGTNLNG");
System.out.println(driver.getPageSource());
Error (in chrome):
You are using an unsupported command-line flag: --ignore-certifcate-errors. Stability and security will suffer
I tried the following solution from Chrome Error: You are using an unsupported command-line flag: --ignore-certifcate-errors. Stability and security will suffer, I installed the latest chromedriver but it didn't resolve my error.
I also tried adding Desired Capabilities (now deprecated) and ChromeOptions as per Pass driver ChromeOptions and DesiredCapabilities?, but the same error persists.
Thanks in advance!
The error says it all :
You are using an unsupported command-line flag: --ignore-certifcate-errors. Stability and security will suffer
As per best programming practices, use the ChromeOptions Class to open Chrome Browser being maximized, disabling the infobars and disabling the extensions as follows :
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
options.addArguments("--test-type");
options.addArguments("--ignore-certificate-errors");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.co.in");
Additionally, perform the following steps :
Update your JDK to the most recent versions JDK 8u162
Upgrade Selenium-Java Clients to v3.10.0.
Upgrade ChromeDriver to the latest release ChromeDriver v2.35
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
For ex my chrome when dropped in the commpand prompt gives me the path
- /Applications/Google\ Chrome.app
I set
System.setProperty("webdriver.chrome.driver", "/Applications/Google/Chrome.app");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
But it doesnt work, same with firefox. I used a lot of suggestions already given but none seems to work. Can someone pls let me know if there is something to be added?
Why have you used "/Applications/Google/Chrome.app". You would need to provide the path of the driver only, not the browser. Below is the code for Firefox, but you would need to download and configure GeckoDriver (for latest version of FF and Selenium 3.x)
public class FirefoxTest {
#Test
public void FirefoxTest_Test1() {
System.setProperty("webdriver.gecko.driver","D:\\Firefox\\geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
}
}
Check this link for complete details for downloading and setup of Geckodriver with Firefox - http://automationtestinghub.com/selenium-3-0-launch-firefox-with-geckodriver/
For Chrome: Need to Download fresh Chrome Driver from http://chromedriver.storage.googleapis.com/index.html?path=2.24/
and mention local system path up to chomedriver.exe
System.setProperty("webdriver.chrome.driver","G:\\ravik\\Ravi-Training\\Selenium\\Drivers\\cd\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeDriver d1 = new ChromeDriver(capabilities);
For FF: if your firefox version is latest(46.0 or above) then user geckodriver along with selenium 2.53.0 jar files. download geckodriver form https://github.com/mozilla/geckodriver/releases and then save it as "wires" in your local system. mention local system path up to wires.
System.setProperty("webdriver.gecko.driver", "G:\\ravik\\Ravi-Training\\Selenium\\Marionette for firefox\\wires.exe");
WebDriver driver = new MarionetteDriver();
Hope this could be helpful.
The easiest way to use chrome driver is.. download and place the driver into the bin folder of your project. no need to set the path of the driver location