0

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)
Dragonthoughts
  • 2,180
  • 8
  • 25
  • 28

2 Answers2

1

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

        }
Sameera De Silva
  • 1,722
  • 1
  • 22
  • 41
0

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.