java - 当我尝试为 Selenium Web 驱动程序创建 GUI 时出现“应用程序启动方法 java.lang.reflect.InvocationTargetException 中的异常”
问题描述
我尝试使用 JavaFX 为 selenium Web 驱动程序项目创建 GUI,但是当我使用 java 8 在 eclipse 上运行此代码时出现此错误。我希望在单击按钮后启动 chrome 并运行测试用例。这是我的代码:
FXML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane prefHeight="200.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.SampleController">
<center>
<Button fx:id="primary" mnemonicParsing="false" onAction="#seleniumLaunch" text="Button" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
控制器类:
在这个按钮功能中,我希望在单击它之后启动 chrome 浏览器,然后转到 baseURL
package application;
import java.net.URL;
import java.util.ResourceBundle;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import selenium.TestCase;
public class SampleController implements Initializable {
TestCase testcase = new TestCase();
@FXML
private Button primary;
@FXML
void seleniumLaunch() {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\driver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseUrl = "http://demo.guru99.com/test/newtours/";
driver.get(baseUrl);
}
@Override // and this
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
错误日志:
Exception in Application start method
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 27 more
Exception running application application.Main
解决方案
推荐阅读
- python - 我的诗歌装置坏了,我不知道从哪里开始修复它
- amazon-web-services - 有没有办法从 AWS Lambda 函数中获取日志流名称?
- julia - VSCode Julia:“安静”编辑
- python - 在 pylatex 中加载自定义文档类
- c# - Visual Studio 2019 - Docker 4.1.1 - 添加容器编排后 Web 应用停止工作
- powershell - “Enter-PSSession -Session”,阻塞调用进程,直到用户键入“exit”
- matlab - 是否有 MATLAB 方法来验证函数是否不满足度量空间的三角不等式?
- r - ShinyDashboard:在默认主题和暗模式之间切换
- numpy - 在大型阵列中使用广播、转置和重塑的 Numpy 速度效率
- python - 过滤任一变量是否包含字符