gpt4 book ai didi

java.lang.module.FindException : while using selenium

转载 作者:太空宇宙 更新时间:2023-11-04 10:09:25 26 4
gpt4 key购买 nike

我对 selenium 相当陌生,我尝试使用教程中使用的一些脚本来进行实践。我下载了所有必需的 .JAR 文件(Chrome 驱动程序、Selenium Java 和独立服务器)并将其添加到 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();
}
}

在执行此操作时,我收到此错误:

    "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.

最佳答案

试试这个,只需编辑路径和包名称。

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

关于java.lang.module.FindException : while using selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52530240/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com