I am getting the below error for the below script. I have all the jar files added to the library.
============================================================
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 webdriver/Demo.Sample.main(Sample.java:11)
=============================================================
package Demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Sample {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("hello");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
}
}
Seems like, you have imported the wrong jar files. Download the selenium-server-standalone-2.53.1.jar file from https://selenium-release.storage.googleapis.com/index.html?path=2.53/ and import it into an eclipse and remove other jar files.
Since you are trying to automate Firefox using Selenium WebDriver, you need to download Firefox executable binary file as well. Based on your browser version, you can get gecko driver from https://github.com/mozilla/geckodriver/
And add the below line in your code before the driver initialization and provide absolute path of Firefox executable binary file with name and extention :
System.setProperty("webdriver.firefox.driver", "pathToGeckoBinaryExecutable");
Below is your modified code :
package Demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Sample {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.driver", "pathToGeckoBinaryExecutable\\geckodriver.exe"); // Provide your system path to the gecko driver with name and extension here
System.out.println("hello");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
}
}
I hope it helps...
Related
Code trials:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeIntro {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\ramak\\Downloads\\chromedriver_win32.zip.exe" );
WebDriver driver=new ChromeDriver();
}
}
Snapshot:
chromedriver_win32.zip is a zip type file a format for compressed file archives, allowing packaging of multiple files and directories into a single file.
Where as System.setProperty() line expects the absolute path of the ChromeDriver binary executable.
Solution
You need to unzip the chromedriver_win32.zip and pass the absolute path of the ChromeDriver binary executable as follows:
System.setProperty("webdriver.chrome.driver","C:\\Users\\ramak\\Downloads\\chromedriver_win32\\chromedriver.exe" );
package path hi friends,
am sorry to post this question as i know this question was already answered many times but the reason i post is am new to java, selenium & eclipse.
have browsed through the answers and infact tried some of the solutions but still facing the below error message.
Error: Could not find or load main class seleniumpackage.Sample
below is my simple program in which i try to open chrome browser and access facebook home page.
package seleniumpackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Sample {
public WebDriver good;
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:/Users/hp/Downloads/Chrome/chromedriver.exe");
WebDriver good = new ChromeDriver();
good.get("https://www.facebook.com/");
}
}
have added chrome browser, selenium client, referenced libraries jar files etc but still facing the error.
please help.
I am getting an error saying "The method window() is undefined for the type Object" and not sure why. This is what my code looks like:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Maximize2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.get("https://login.yahoo.com/");
driver.manage().window().maximize();
}
}
The snippet above works for me with Selenium 2.53.1, Firefox 51.0.1 and Fedora 25.
Try to update your Selenium and browser and run the test again.
Try to do the setup for Eclipse like this:
Download and unzip Selenium Client Driver for Java
http://seleniumhq.org/download/#client-drivers
Create a new project
Right click on project in Package Explorer
Click “Properties”, then “Java Build Path”
Click “Add External JARs” and select all jar files from “libs” folder and "selenium-java-$VERSION.jar"
Run the snippet again
You should also consider using Gradle for your dependency management. This tutorial and googling for "gradle selenium" should help: https://gradle.org/uncategorized/video-tutorial-test-automation-selenium-web-application/
I'm trying to run the following sample snippet
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test
{
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
//System.out.println("My new program");
}
}
When I run this code, getting the following error.
The path to the driver executable must be set by the webdriver.gecko.driver system property;
Firefox version is 48.0
Could anyone please help me to fix this issue.
If you are using windows follow the steps:
Right click my computer and select properties.
Click advanced settings->Environment variables.
Under System variable there should be variable named Path.
By the end of the path variable value add semi colon and then add specify your jecko driver's path. Example(C:\Jeckodriver).
Now compile the code. If it still throws exception then downgrade Firefox to 47.0.1.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test
{
public static WebDriver driver;
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver","Browser path.exe");
driver = new FirefoxDriver();
driver.get("http://www.google.com");
//System.out.println("My new program");
}
}
Download Gecko driver and extract to any folder. Specify gecko driver's path in path variable.
I am new to Selenium and I am trying to access google.co.in. My code is
public static void main(String[] args) {
String baseUrl = "https://www.google.co.in/";
WebDriver driver = new FirefoxDriver();
driver.get(baseUrl);
}
But I am getting an error which says Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
and I have also written two import statements after loading the appropriate jar file
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
I am new to both selenium and java..So please help..
You must add this library:
selenium-server-standalone-version.jar
and
selenium-java-version.jar
download here: Selenium Downloads