Autosuggestion for driver is not working on Selenium on Eclipse - selenium

I am trying to create my first automation test and when I try to get autosuggestions for driver ( the get(string) one), nothing appears. Also multiple error appear. IS there anything, like other extensions, that I need to install or what might be the problem?
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Demo {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\test\\chromedriver.exe");
WebDriver driver = new Chromedriver();
driver.
}
}
The following errors appear:
Multiple markers at this line
The type org.openqa.selenium.WebDriver is not accessible
Must declare a named package because this compilation unit is associated to the named module
'Introduction'(for line 1)
The type org.openqa.selenium.chrome.ChromeDriver is not accessible (for line 2)
Multiple markers at this line
WebDriver cannot be resolved to a type
Chromedriver cannot be resolved to a type( for line 10)

Related

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

Exception in thread Unresolved compilation problems:

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();
}
}

org.openqa.selenium.InvalidArgumentException: Invalid argument

I'm new to this site and I would like to request your help and expert opinion on this issue.
I'm currently trying to run a simple code using Netbeans and Selenium, but everytime I run the code I get the error "Exception in thread "main" org.openqa.selenium.InvalidArgumentException: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir"
This is the code I'm trying to run, something weird is that I can successfully run the same code on a different computer.
package selenium.test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeleniumTest {
private static WebDriver driver = null;
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\Kevin\\Documents\\Selenium\\Driver\\chromedriver.exe");
driver = new ChromeDriver();
driver.get ("https:\\www.google.com");
}
}
Chrome Version: 77.0.3865.90
ChromeDriver Version: 77.0.3865.40
Netbeans: 8.2
Thank you very much for your help
Use ChromeOptions. You can specify a directory that's not your user's directory:
ChromeOptions co = new ChromeOptions();
co.addArguments("user-data-dir=C:\\Some\\valid\\data dir\\");

Cannot resolve method addArguments(java.lang.String) - Selenium with Chrome

I'm new to Selenium and in my code I'm trying to use my default profile from chrome with the browser that the selenium opens (without the cookies.)
Here is my code:
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.chrome.ChromeOptions;
public class tryf {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\******\\Downloads\\chromedriver_win32\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:\\Users\\******\\AppData\\Local\\Google\\Chrome\\User Data");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com");
driver.manage().window().maximize();
//WebElement okStart;
//okStart = driver.findElement(By.id("close-instructions"));
//okStart.click();
}
}
My problam is that the code won't compile, with that eror
Error:(15, 16) java: no suitable method found for addArguments(java.lang.String)
method org.openqa.selenium.chrome.ChromeOptions.addArguments(java.lang.String...) is not applicable
(argument mismatch; java.lang.String cannot be converted to java.lang.String[])
method org.openqa.selenium.chrome.ChromeOptions.addArguments(java.util.List) is not applicable
(argument mismatch; java.lang.String cannot be converted to java.util.List)
Hope for help, Thanks :)
You are passing a string parameter in following statement.
options.addArguments("user-data-dir=C:\Users\******\AppData\Local\Google\Chrome\User Data");
The string parameter is not applicable as highlighted by the stacktrace.
method org.openqa.selenium.chrome.ChromeOptions.addArguments(java.util.List) is not applicable
(argument mismatch; java.lang.String cannot be converted to java.util.List)
You can look at the documentation to find which method meets your requirements.
The overloaded addArguments methods signature are below;
ChromeOptions addArguments(java.util.List<java.lang.String> arguments)
Adds additional command line arguments to be used when starting Chrome.
ChromeOptions addArguments(java.lang.String... arguments)

Error in selenium webDriver while executing the normal test case

Here is my code for selenium webDriver
package com.pack;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GoogleSearchTest {
public static void main(String...args) {
WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://google.com");
String appTitle = driver.getTitle();
System.out.println("Application title is :: "+appTitle);
driver.quit();
}
}
Below is the Error I am getting:
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 com.pack.GoogleSearchTest.main(GoogleSearchTest.java:9)
I need to understand why I am getting that error.
Looks like you are trying to run the code that is already having compilation issues. You should be seeing a tab called "Problems", where it shows all/ any possible errors and warnings. Do you see anything in that tab? If so it will walk through the steps that you need to follow to overcome the issue.
The other option is to download a fresh copy of eclipse IDE and configure your selenium. Let me know which one worked for you.