Exception in thread Unresolved compilation problems: - selenium

This is my script:
package sampleTests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AdminLogin {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver(); //Launches Firefox Browser with blank url
driver.close();
}
}
When I run the script, am getting below error, I tried to add the java lib in Class path instead of Module path, still the issue not resolved, someone please help;
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type FirefoxDriver cannot be resolved to a type at sampleTests.AdminLogin.main(AdminLogin.java:10)

You have to set the path of the Geckodriver (the executable that is used for Firefox tests using Selenium).
Search for Geckodriver in Google.
Download the executable as per your system (Win/Mac/Linux)
Set the path of the executable in your tests as given below -
package sampleTests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AdminLogin {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver",Path_of_Firefox_Driver");
// example for Windows
System.setProperty("webdriver.gecko.driver",D:\\GeckoDriver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://testautomationu.applitools.com/");
driver.quit();
}
}

Related

Selenium not opening the browser and the code instead runs in JAVA console and throws error message

package firstSeleniumTesting;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class testingAutomation {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.drive", "C:\\SeleniumDriver\\chromedriver_win32");
WebDriver driver = new ChromeDriver(); //Launches Firefox
driver.close();
}
}
I get the following error
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from https://chromedriver.storage.googleapis.com/index.html
at org.openqa.selenium.internal.Require$StateChecker.nonNull(Require.java:280)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:132)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:38)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:231)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:434)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:127)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:46)
at firstSeleniumTesting.testingAutomation.main(testingAutomation.java:13)
Add the .exe in the chromedriver
Use like this
System.setProperty("webdriver.chrome.driver", "C:\\SeleniumDriver\\chromedriver_win32.exe");
WebDriver driver = new ChromeDriver();
driver.close();

I am unable to launch the Chrome browser even though the key and values is correct in system.set property file

package selsample;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class selclass[enter image description here][1] {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\Users\\username\\Selenium.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://app.doselect.com/test/bvd9b/feedback");
}
}
The chromedriver.exe is not available in the mentioned that's why it shows driver executable does not exist, you can set it as below
Create a folder in your project named driver just copy the chromedriver.exe to that folder (eg. /driver/chromedriver.exe)
String path = System.getProperty("user.dir");
System.setProperty("webdriver.chrome.driver",path+"\\driver\\chromedriver.exe");
You check this that might help you just follow the steps

Error while invoking Internet Explorer browser using Selenium

Can anyone please help with the Selenium code below. I am getting an error while invoking Internet Explorer for automation testing.
Code :
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Demo {
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver","C:\\microsoftwebdriver\\MicrosoftWebDriver.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("https://www.google.com/");
System.out.println(driver.getTitle());
}
}
Error screenshot attached:
InternetExplorerDriver
InternetExplorerDriver class is the WebDriver implementation that controls the IEServerDriver and and allows you to drive Internet Explorer browser running on the local machine. This class is provided as a convenience for easily testing the InternetExplorer browser. The control server which each instance communicates with will live and die with the instance.
To create a new instance of the IEServerDriver you need to use the IEServerDriver binary instead of MicrosoftWebDriver.exe which you need to download from selenium-release.storage, unzip and provide the absolute path within the System.setProperty() line. So your effective code block will be:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Demo {
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver","C:\\path\\to\\IEServerDriver.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("https://www.google.com/");
System.out.println(driver.getTitle());
}
}

Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Selenium\geckodriver.exe

I am getting below exception while trying to open a site
Exception in thread "main" java.lang.IllegalStateException: The driver
executable does not exist: C:\Selenium\geckodriver.exe at
com.google.common.base.Preconditions.checkState(Preconditions.java:534)
at
org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136)
at
org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:131)
at
org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
at
org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:141)
at
org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
at
org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:158)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:98)
at com.tst.Test.main(Test.java:12)
My code is:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:/Selenium/geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.co.in");
I am using selenium 3 with geckodriver-v0.19.1-win64.zip. and java version is 1.8.
Please help me out
You need to setPath properly for binary file. On windows, I prefer \\ instead od /, Can you please try this?-
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:\\Selenium\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.co.in");

Selenium webdriver running issue

I am trying to running selenium webdriver using eclipse.Unfortunately i face the following issue:
click here for the snapshot
and the code is,
package myproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class MyClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver", "K:\\New folder\\geckodriver-v0.18.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver(); driver.get("http://only-testing-blog.blogspot.in");
String i = driver.getCurrentUrl();
System.out.println(i); driver.close();
}
}
UPDATE:
If you right click on your project and "Run as... Java application" and you have multiple main methods in your project, eclipse doesn't know which one to start so it asks which class. The solution is to right click on your class and "Run as...". After that you can just press "Run".