1

I am fairly new to selenium, and I was trying to use some of the scripts being used in tutorials for my practice. I downloaded all the required .JAR files (Chrome drivers, Selenium Java and Stand Alone server) and added it to the path in Eclipse.

 Below is the Code which I am trying to run to access a Weblink and then trying to verify if a user is able to log in successfully or not. 

      package learnautomation;

      import org.openqa.selenium.By;
      import org.openqa.selenium.WebDriver;
      import org.openqa.selenium.chrome.ChromeDriver;

      public class practice {

public static void main(String[] args) {

    System.setProperty("webdriver.chrome.driver", "Mypath\\chromedriver.exe");


    WebDriver driver = new ChromeDriver();

    driver.get("http://www.gcrit.com/build3/admin/");
    driver.findElement(By.name("username")).sendKeys("admin");
    driver.findElement(By.name("password")).sendKeys("admin@123");
    driver.findElement(By.id("tdb1")).click();

    String url = driver.getCurrentUrl();

    if (url.equals("http://www.gcrit.com/build3/admin/index.php")){
    System.out.println("Successful"); 
    }
    else {
    System.out.println("Unsuccessful");
    }
    driver.close();
    }
    }

While doing this I am getting this error:

    "Error occurred during initialization of boot layer
     java.lang.module.FindException: Module seleniumnew not found"  

   Also, import org.openqa.selenium.chrome.ChromeDriver; it says this is not accessible as well when I just hover over it.   
Avi
  • 1,795
  • 3
  • 16
  • 29

1 Answers1

0

try this, just edit paths and package name.

package navi;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Avi {
    public static WebDriver driver;
    WebDriverWait wait5s = new WebDriverWait(driver,5); 

    @BeforeClass
    public static void setUpClass() {
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\pburgr\\Desktop\\chromedriver\\chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("user-data-dir=C:\\Users\\pburgr\\AppData\\Local\\Google\\Chrome\\User Data");
        driver = new ChromeDriver(options);
        driver.manage().window().maximize();}   
    @Before
    public void setUp() {}
    @After
    public void tearDown() {}
    @AfterClass
    public static void tearDownClass() {driver.close();driver.quit();}
    @Test
    public void avi() throws InterruptedException {
        driver.get("http://www.gcrit.com/build3/admin/");
        wait5s.until(ExpectedConditions.elementToBeClickable(By.name("username"))).sendKeys("admin");
        driver.findElement(By.name("password")).sendKeys("admin@123");
        driver.findElement(By.id("tdb1")).click();

        // wait to resolve the click before checking url
        Thread.sleep(1000);

        String url = driver.getCurrentUrl();

        if (url.equals("http://www.gcrit.com/build3/admin/index.php")){
        System.out.println("Successful"); 
        }
        else {
        System.out.println("Unsuccessful");
        }
    }
}
pburgr
  • 1,722
  • 1
  • 11
  • 26
  • @pbugr Unfortunately I am still getting an error for some reason, when I am trying to run from Python, same credentials and path works while Java is throwing me the same error. – Avi Sep 28 '18 at 04:41