当前位置: 首页 > 知识库问答 >
问题:

java.lang.module.使用硒

王杰
2023-03-14

我对selenium相当陌生,我试图使用一些在教程中使用的脚本来练习。我下载了所有需要的。JAR文件(Chrome驱动程序、SeleniumJava和独立服务器),并将其添加到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.   

共有1个答案

鲜于光赫
2023-03-14

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

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");
        }
    }
}
 类似资料:
  • 我在Eclipse4.7中创建了一个新的Java10项目。3a 这是一个带有一些依赖关系的maven项目。 该项目称为“MyProject”,下面是我的模块信息。JAVA 当我运行该项目时,我得到以下信息 我做错了什么?

  • 我试图在Intellij 2018.3 IDE中构建示例javaFX应用程序。我已经安装了OracleJDK11,并下载了openjfk11。我创建了一个链接到JavaFXSDK的库,并在VM选项行中添加了一行--module path=${path_to_FX}--add modules=javafx.controls,javafx.fxml。路径_到_FX定义为指向我的javaFX文件夹的环境

  • 有没有办法在使用 jongo 查询 MongoDB 时添加 ?我发现这样的错误 - '排序超出了 104857600 字节的内存限制,但没有选择加入外部排序。正在中止操作。传递 allowDiskUse:true 可以选择加入,可以通过以下方式阻止,您的聚合看起来像 但据我所知,Jongo 中的类仅将管道应用于自身,然后您可以使用 方法执行。 是否有任何方法可以将该参数传递给mongo而不从Jon

  • 问题内容: 我在远程服务器上有一个管理Web应用程序。该应用程序是使用MEAN堆栈编写的,我列出了连接到Web应用程序所需的所有RESTful路由。 我正在编写一个Java客户端应用程序,该应用程序需要从该管理应用程序发送和接收数据。如果我具有服务器的IP地址和REST路由,如何将客户端连接到Web应用程序? 我想我需要提供到服务器和REST API文件的URL连接,然后仅调用诸如和的路由功能。

  • 问题内容: 我使用spring数据和方法来获取模型。调用此方法时如何使用查询提示? 上面的源代码工作正常,但是我不能为我的JPA提供程序(在我的情况下为EclipseLink)设置QueryHint。 以上是我使用spring-data使用查询提示的方式, 我还发现了这个尚未解决的问题。 问题答案: 当我想使用spring-data创建查询时,请遵循上述算法。 1)是否已经提供的查询 通过弹簧数据

  • 我使用spring数据和方法获取模型。调用此方法时如何使用查询提示 上面的源代码运行良好,但我无法为我的JPA提供者(在我的例子中是EclipseLink)设置QueryHint。 我使用spring数据使用查询提示的方式如下:, 我也发现这个还没有解决。