Not Able to open Chrome browser in Selenium.
Here is the code:
package toolsqa;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestChrome {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\MR049860\\Documents\\Selenium\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
}
}
I'm getting the following Exception:
Exception in thread "main" 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:339)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at toolsqa.TestChrome.main(TestChrome.java:14)
The error says it all :
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
While mentioning the Key and Value within System.setProperty() you have to escape the back slashes (\\). Hence, you need to change the line :
System.setProperty("webdriver.chrome.driver","C:Path\chromedriver.exe");
To :
System.setProperty("webdriver.chrome.driver","C:\\absolute_path\\to\\chromedriver.exe");
Related
I have basic file and running the java file, throws No classDeffoundError: io/netty/util/Timer at
packkage cucumber ;
public class seleniumTesting{
System.setproperty("webdriver.chrome.driver", ".\\downloads\chromedriver.exe");
WebDriver driver = new Chromedriver();
please suggest where is the issue.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class test {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/Users/alcodesmobility/Desktop/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.browserstack.com/");
Actions action = new Actions(driver);
WebElement element = driver.findElement(By.linkText("Get started free"));
action.moveToElement(element).click();
//using click action method
}
}
Starting ChromeDriver 89.0.4389.23
(61b08ee2c50024bab004e48d2b1b083cdbdac579-refs/branch-heads/4389#{#294})
on port 24715 Only local connections are allowed. Please see
https://chromedriver.chromium.org/security-considerations for
suggestions on keeping ChromeDriver safe. ChromeDriver was started
successfully. [1622542783.292][WARNING]: This version of ChromeDriver
has not been tested with Chrome version 90. Jun 01, 2021 3:49:43 PM
org.openqa.selenium.remote.ProtocolHandshake createSession INFO:
Detected dialect: W3C Exception in thread "main"
java.lang.ClassCastException: class
org.openqa.selenium.remote.RemoteWebElement cannot be cast to class
org.openqa.selenium.interactions.internal.Locatable
(org.openqa.selenium.remote.RemoteWebElement and
org.openqa.selenium.interactions.internal.Locatable are in unnamed
module of loader 'app') at
org.openqa.selenium.interactions.Actions.moveToElement(Actions.java:387)
at CronberrySignin.test.main(test.java:22)
I guess you are missing completing the move to element code line.
Try this instead:
action.moveToElement(element).click(element).build().perform();
There is no need to implement Actions class, the element is in Selenium viewport right from the page loading.
use id instead.
driver.findElement(By.id("signupModalButton")).click();
Read when to use actions class here
and by reading exception stack trace, it looks like driver issue. Make sure to use inline version of Selenium webdriver, chromedriver, and chrome broswer.
When i am trying to invoke chrome browser in eclipse using selenium driver with Java , i am getting an error.
Please help me out in resolving this issue.
Below is my code -
package packagedefault;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ChromeBrowser {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://google.com");
}
}
Below is the error message i am getting -
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/config/RegistryBuilder
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:69)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:57)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:60)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.getDefaultHttpClientFactory(ApacheHttpClient.java:242)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.<init>(ApacheHttpClient.java:219)
at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:93)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:72)
at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:63)
at org.openqa.selenium.chrome.ChromeDriverCommandExecutor.<init>(ChromeDriverCommandExecutor.java:36)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at packagedefault.ChromeBrowser.main(ChromeBrowser.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.http.config.RegistryBuilder
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more
You can try using below code inside main() function
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--test-type");
WebDriver driver = new ChromeDriver(options);
driver.get("https://google.com");
Works properly here in my windows PC
Exception you mentioned
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/http/config/RegistryBuilder
Occured when jars files are not available.
Import only the selenium-server-standalone- jars and try your code .
System.setProperty("webdriver.chrome.driver", "Path of chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://google.com");
I'm trying to run selenium webdriver program, getting following error :
Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.io.FileHandler.unzip(Ljava/io/InputStream;)Ljava/io/File;
Firefox version : 47.0.1
Selenium version : 2.53.1
Eclipse : Oxygen Release (4.7.0)
import org.apache.xpath.XPathContext;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class PG1
{
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://demo.guru99.com/selenium/newtours/");
System.out.println("The title of page is : " + driver.getTitle());
driver.close();
}
}
This program was working fine in another laptop, but not working on new laptop/setup.
Can someone please help.
Error I'm getting :
Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.io.FileHandler.unzip(Ljava/io/InputStream;)Ljava/io/File;
at org.openqa.selenium.firefox.internal.FileExtension.obtainRootDirectory(FileExtension.java:82)
at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:59)
at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:64)
at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:443)
at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:421)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:85)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.startClient(RemoteWebDriver.java:303)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:125)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:218)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at bitbfw.PG1.main(PG1.java:11)
Found what was wrong..
it was that in "Java Build Path", the JRE system library was not added earlier. I went to configure Build path-->Add Jars selected "jRE system library", Applied & Closed.
Then on all the programs worked fine.
This question already has answers here:
Official reasons for "Software caused connection abort: socket write error"
(14 answers)
Closed 7 years ago.
My settings :
TestNG 6.9.10 - Java 1.8 - Eclipse Mars.1 Release (4.5.1)
Windows 10
Every time I run a TestNG test suite I have this error :
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(Unknown Source)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(Unknown Source)
at java.io.ObjectOutputStream.<init>(Unknown Source)
at org.testng.remote.strprotocol.SerializedMessageSender.sendMessage(SerializedMessageSender.java:24)
at org.testng.remote.strprotocol.MessageHub.sendMessage(MessageHub.java:43)
at org.testng.remote.RemoteTestNG$RemoteSuiteListener.onStart(RemoteTestNG.java:257)
at org.testng.SuiteRunner.invokeListeners(SuiteRunner.java:208)
at org.testng.SuiteRunner.run(SuiteRunner.java:266)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)
Even if my test class is empty :
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class sample {
public WebDriver driver;
#Test
public void f() {
}
#BeforeTest
public void beforeTest() {
driver = new FirefoxDriver();
driver.get("http://localhost:8081/login.html?profile=desktop");
}
#AfterTest
public void afterTest() {
driver.close();
}
}
The test is running, so it doesn't interfere with the test case, but I really would like to understand and remove this Exception.
Thank you for any idea.
I'm thinking somewhere in WebDriver, java.net is used. Your localhost webserver is closing the socket or it was closed prematurely. Instead of using Before and After test, try to write it all in one Test method and debug. Unfortunately, there's no mention of your class in the stack trace to pinpoint which call is causing the problem.
Step through the following and see where the exception is thrown. If it's on the driver.get call, then your http server is likely rejecting the connections. If it's thrown at the close(), the connection has already been dropped (probably rejected by the server).
#Test
public void test() {
driver = new FirefoxDriver();
driver.get("http://localhost:8081/login.html?profile=desktop");
driver.close();
}