This question already has answers here:
java.lang.Error: Unresolved compilation problems : WebDriver/ChromeDriver cannot be resolved to a type error while executing selenium tests
(5 answers)
Closed 3 years ago.
Question is:
1) In my simple program how do I identify errors in each line before run it?
2) I placed my program here, while running I am getting many errors. How can I resolve them?
Program:
package newpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Myclass {
public static void main(String[] args) {
System.out.println("Chrome is selected");
System.setProperty("webdriver.chrome.driver","C:\\ProgramFiles\\Chrome65.0.3325.146\\googlechromeportable.exe");
WebDriver driver= new ChromeDriver();
driver.get("https://www.facebook.com/");
driver.manage().window().maximize();
//XPath for Email Field
driver.findElement(By.xpath("//*[#id='login']")).sendKeys("xxx#gmail.com");
//XPath for Password Field
//driver.findElement(By.xpath("//*[#id='pass']")).sendKeys("xxxxxxx");
driver.findElement(By.xpath("//*[#id=\"u_0_a\"]")).click();
}
}
Error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type
ChromeDriver cannot be resolved to a type
By cannot be resolved`enter code here`
By cannot be resolved
at newpackage.Myclass.main(Myclass.java:16)
You need to specify the driver location , by mistake you gave the browser.exe path so kindly modify your code as below . My chromedriverexe in Jar_files folder and you may need to download it and place it there . I advise you to refer a blog or a video prior to scripting so that you can get more clear idea.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class ExecutionbasedOnTReachabilityOfSite {
WebDriver driver;
#BeforeClass()
public void setUp() throws IOException {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\Jar_files\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
// To start Chrome in Maximized browser window
options.addArguments("start-maximized");
// To remove Chrome is being controlled by automated test software
options.addArguments("disable-infobars");
driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
It is because you have not added selenium-server-standalone-3.141.59.jar as dependency in build path.
Download JAR from below path:
https://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar
Right click on Project Folder > Build Path > Configure Build Path > Select & Add downloaded external JAR
All compile time errors that you are getting will be resolved.
Related
I'm trying to play with the Selenium 4 features in eclipse with java but can't seem to get them to work, which i'm assuming must be my mistake in configuration, so I'd appreciate if anyone can explain where i'm going wrong and how I can correct it?
Code below: I get an error warning on the last line (containing the newWindow() method) and the error message is as per the Title of this post.
I've downloaded the selenium-java-4.0.0-alpha-4 from here https://selenium-release.storage.googleapis.com/index.html?path=4.0-alpha4/
i've created a new eclipse java project, and unzipped and included all of the jar files in my java build path, but it doesn't seem to recognise / or be able to find the newWindow() method
package practice;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WindowType;
import org.openqa.selenium.chrome.ChromeDriver;
import static org.openqa.selenium.support.locators.RelativeLocator.withTagName;
import org.openqa.selenium.By;
public class Sel4alpha4 {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\me\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
driver.switchTo().newWindow(WindowType.TAB); // this line has the error
}
}
There might be two problems:
1) Incorrect Import- You should import the following:
org.openqa.selenium.WindowType;
2) Issue with the version you are using. Try to upgrade the selenium version.
Version:
selenium 4.0.0-beta-4
Please try to download the updated jar from the below link:
https://www.selenium.dev/downloads/
or
https://selenium-release.storage.googleapis.com/index.html?path=4.0-beta-4/
this is my class*****
```
package automation;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Test1 {
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:/Users/UMASHANKAR/Downloads/chromedriver_win32/chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.findElement(By.id("userName")).sendKeys("https://sdzclient-kpiregister.azurewebsites.net/");
driver.findElement(By.id("passwords")).sendKeys("Gravity#123");
driver.findElement(By.id("btn-sdz-login")).click();
}
}
```
on Hover the SendKeys method will get an error like"The method sendKeys(char sequence[] )in the type webelement is not applicable for the string".***
When you are working with Selenium you need to follow a few steps
//first you add your chrome driver path
System.setProperty("webdriver.chrome.driver", "C:/Users/UMASHANKAR/Downloads/chromedriver_win32/chromedriver.exe");
// second you need to initialize the WebDriver object - and you did it
WebDriver driver=new ChromeDriver();
// third you need to tell to the WebDriver object where to go, what page to load
driver.get("https://sdzclient-kpiregister.azurewebsites.net/");
//below is the login part
driver.findElement(By.id("userName")).sendKeys("SET_YOUR_USERNAME_HERE");
driver.findElement(By.id("passwords")).sendKeys("Gravity#123");
driver.findElement(By.id("btn-sdz-login")).click();
your error was throw because the driver didn't know where to go but you tried to send some keys instead of a driving page path
I am not sure, when you said you are not able to change compilation version. You can change as per below screen grab.
..project>right click>build path>configure build path >java compiler>
Do not forget to click on Apply after changing compilation version.
How to fix Selenium DesiredCapabilities giving Error 'not resolved to a type' while using with WebdriverManager and ChromeOptions
package pack.tests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.annotations.BeforeTest;
import org.openqa.selenium.remote.CapabilityType;
//Error The import org.openqa.selenium.remote.CapabilityType cannot be resolved
import org.openqa.selenium.remote.DesiredCapabilities;
//Error The import org.openqa.selenium.remote.DesiredCapabilities cannot be resolved
import io.github.bonigarcia.wdm.WebDriverManager;
public class TestGuru99Login{
#BeforeTest
public void Setup() {
WebDriverManager.chromedriver().setup();
ChromeOptions option = new ChromeOptions();
option.addArguments("--test-type");
option.addArguments("--disable-popup-bloacking");
option.addArguments("--incognito");
DesiredCapabilities chrome = DesiredCapabilities.chrome();
/*Error
Multiple markers at this line - DesiredCapabilities cannot be resolved -
* DesiredCapabilities cannot be resolved to a type*/
chrome.setJavascriptEnabled(true);
chrome.setCapability(ChromeOptions.CAPABILITY, option);
WebDriver driver = new ChromeDriver(option);
//Error:Type mismatch: cannot convert from ChromeDriver to WebDriver
driver.get("https://toolsqa.com");
driver.quit();
}
}
org.openqa.selenium.remote.DesiredCapabilities
Above one is coming from the selenium remote driver module. You can add the following in your POM.xml and try out. You can change the "version" number based on your compatibility with other selenium module.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>4.0.0-alpha-3</version>
</dependency>
This solution seems to be working in my case. Anybody else facing this issue, all other above solutions are not working.
This happens when you have added the external jars in the ModulePath.
Solution:
enter code hereRemove the external jars from the node "Modulepath". Select the node "Classpath" then add the external jars. Check selenium jar is imported.
This question already has answers here:
ChromeDriver and WebDriver for Selenium through TestNG results in 4 errors
(2 answers)
java.lang.Error: Unresolved compilation problems : WebDriver/ChromeDriver cannot be resolved to a type error while executing selenium tests
(5 answers)
Closed 2 years ago.
I'm new to selenium and I tried to code my first java script using selenium.
It is giving errors as follows:
**- WebDriver cannot be resolved to a type
ChromeDriver cannot be resolved to a type
Watchpoint:FirstSelleniumScript [access and modification] - driver**
I have added selenium to the libaries- selenium-java-3.141.59
java version "1.8.0_251"
I can't understand how to fix it.
Import Necessary Files
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
Download The Compatible
ChromeDriver
Now in function you have set the path for chromedriver in your method
String chromePath = "C:/Common_Resourses/";
System.setProperty("webdriver.chrome.driver", chromePath + "chromedriver.exe");
WebDriver driver = new ChromeDriver();
You can also Read more About browser capabilities, it will help you with browser handling
You need to set property first and import chrome driver.
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", "path of the exe file\\chromedriver.exe");
// Initialize browser
WebDriver driver=new ChromeDriver();
Also refer this video https://youtu.be/c86GdHQaLsY
I have prepared the environment for test automation of Android Application using eclipse. I have followed the instruction from the below site:
https://code.google.com/p/selenium/wiki/AndroidDriver#Setup_the_Environment
I have copied the following code from the above website as below:
import junit.framework.TestCase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidDriver;
public class OneTest extends TestCase {
public void testGoogle() throws Exception {
WebDriver driver = new AndroidDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
But error as "WebDriver cannot be resolved to a type" was found at the following line:
WebDriver driver = new AndroidDriver();
Note: I have added "selenium-server-standalone-2.33.0.jar" to Java Build Path
Only one import statement is needed to fix the error. import the following and that's it:
import org.openqa.selenium.WebDriver;
You need to properly install the android server available here http://code.google.com/p/selenium/downloads/list .
Follow this tutorial http://code.google.com/p/selenium/wiki/AndroidDriver#Install_the_Android_SDK
regarding how to install the android web driver.
Add - import org.openqa.selenium.WebElement;