Error in selenium webDriver while executing the normal test case - selenium

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.

Related

Autosuggestion for driver is not working on Selenium on Eclipse

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)

Web page stuck with loading bar while executing the automation script using Selenium?

I'm executing the automation script, in which I am facing loading bar for infinite time on the specific web page.
I have confirmed that issue is not from script side because earlier same scripts are executing fine.
I have applied the solutions as below.
Executing the script in other browsers
Increase wait time
Updated Chrome browser/chromedriver.exe
Currently I'm using below tools/version
Chrome Version: 89.0.4389.82
Chrome driver[Version:ChromeDriver89.0.4389.23]
Java [version: 11]
Selenium WebDriver
Can anyone please provide me the solutions?
Thanks in advance
Try changing the page load strategy to "eager":
This will make Selenium WebDriver to wait until the initial HTML document has been completely loaded and parsed, and discards loading of stylesheets, images and subframes.
When set to eager, Selenium WebDriver waits until DOMContentLoaded event fire is returned.
Example usage:
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;
public class pageLoadStrategy {
public static void main(String[] args) {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
WebDriver driver = new ChromeDriver(chromeOptions);
try {
// Navigate to Url
driver.get("https://google.com");
} finally {
driver.quit();
}
}
}

WebDriver cannot be resolved to a type ChromeDriver cannot be resolved to a type [duplicate]

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.
I am using all latest versions as in below but still see the issue said in above. Can someone help with it.
Eclipse IDE Version: 2019-12 (4.14.0);
WebDriver (Java) - 3.141.59
ChromeDriver 79.0.3945.36
Here is my code:
package AutomationFrameWork;
import org.openqa.selenium.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
org.openqa.selenium.chrome.*;
public class FirstTestCase {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver", "C:\\Users\\xxxx.000\\Desktop\\Selenium\\chromedriver_win32\\chromedriver.exe");
driver.get("www.google.ca");
System.out.println("Successfully opened the website");
driver.quit();
}
}
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
at AutomationFrameWork.FirstTestCase.main(FirstTestCase.java:15)
You need to give like this .Also better to put in a folder than putting on the desktop.
WebDriver driver;
System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir")+"\\Jar_files\\chromedriver.exe");
driver = new ChromeDriver();
System.setProperty() should be prior to driver intialization.
Also check version of chrome browser and chrome driver are in sync.

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\\");

Running Seleniuem web driver 2.53.0 with Firefox 47.0

I have just started running test scripts using selenium web driver. I coded the following code as a start.
package myPackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class myTest {
public static void main(String[] args){
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
}
}
When I run it as Java application, It always shows the following error message.
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Just the browser opens, but the facebook page doesn't get opened.
What is the solution for this?