尝试使用已编译的JavaFX应用程序运行Webdriver

时间:2014-07-10 01:14:42

标签: java exception intellij-idea javafx webdriver

我正在使用优秀的webdriver框架构建应用程序。首先,我想指出我对Java非常陌生。大约3-4天前开始学习它,并认为到目前为止使用起来很棒!我正在使用IntelliJ(我使用PyCharm,因此对我来说这是一个明显的选择)

无论如何,直到问题。我开始编写代码并且一切顺利,然后我决定我应该在GUI上开始。所以我在IntelliJ中创建了一个新的JavaFX应用程序,添加了我现有的代码,创建了一个按钮(w00t,转到我!)并制作它以便运行一个方法来加载一个chromedriver实例并加载一个网页。当我在IntelliJ中运行时,它按预期工作。然而,当我构建工件时,我无法让它工作。应用程序加载我闪亮的GUI,我点击按钮,没有任何反应。最初我认为chromedriver的目录是错误的,所以我设置了它的绝对路径(我知道这是正确的)。它仍然没有奏效。然后我尝试使用java -jar JavaFXApp.jar加载应用程序。它加载正常,单击按钮,然后我有一大堆错误。我环顾四周,但由于我是一个菜鸟,无法理解。 这是输出

  
    

线程中的异常" JavaFX应用程序线程"了java.lang.RuntimeException:     java.lang.reflect.InvocationTargetException at     javafx.fxml.FXMLLoader $ MethodHandler.invoke(FXMLLoader.java:1768)at at     javafx.fxml.FXMLLoader $ ControllerMethodEventHandler.handle(FXMLLoader.java:1651)       在     com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)       在     com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)       在     com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)       在     com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)       在     com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)       在     com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)       在     com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)       在     com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)       在     com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)       在     com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)       在com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)       在com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)at     javafx.event.Event.fireEvent(Event.java:204)at     javafx.scene.Node.fireEvent(Node.java:8175)at     javafx.scene.control.Button.fire(Button.java:185)at     com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)       在     com.sun.javafx.scene.control.skin.BehaviorSkinBase $ 1.handle(BehaviorSkinBase.java:96)       在     com.sun.javafx.scene.control.skin.BehaviorSkinBase $ 1.handle(BehaviorSkinBase.java:89)       在     com.sun.javafx.event.CompositeEventHandler $ NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)       在     com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)       在     com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)       在     com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)       在     com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)       在     com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)       在     com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)       在     com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)       在     com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)       在     com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)       在     com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)       在com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)       在com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)at     javafx.event.Event.fireEvent(Event.java:204)at     javafx.scene.Scene $ MouseHandler.process(Scene.java:3746)at     javafx.scene.Scene $ MouseHandler.access $ 1800(Scene.java:3471)at at     javafx.scene.Scene.impl_processMouseEvent(Scene.java:1695)at     javafx.scene.Scene $ ScenePeerListener.mouseEvent(Scene.java:2486)at at     com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(GlassViewEventHandler.java:314)       在     com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(GlassViewEventHandler.java:243)       在java.security.AccessController.doPrivileged(Native Method)at     com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:345)       在com.sun.glass.ui.View.handleMouseEvent(View.java:526)at     com.sun.glass.ui.View.notifyMouse(View.java:898)引起:     java.lang.reflect.InvocationTargetException at     sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       在     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       在java.lang.reflect.Method.invoke(Method.java:483)at     sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)at     sun.reflect.GeneratedMethodAccessor1.invoke(未知来源)at     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       在java.lang.reflect.Method.invoke(Method.java:483)at     sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)at     javafx.fxml.FXMLLoader $ MethodHandler.invoke(FXMLLoader.java:1763)...     43更多引起:java.lang.NoClassDefFoundError:     org / openqa / selenium / NoSuchElementException at     BetBot.Controller.TestT(Controller.java:16)... 53更多引起:     抛出java.lang.ClassNotFoundException:     org.openqa.selenium.NoSuchElementException at     java.net.URLClassLoader $ 1.run(URLClassLoader.java:372)at     java.net.URLClassLoader $ 1.run(URLClassLoader.java:361)at     java.security.AccessController.doPrivileged(Native Method)at     java.net.URLClassLoader.findClass(URLClassLoader.java:360)at     java.lang.ClassLoader.loadClass(ClassLoader.java:424)at     sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308)at at     java.lang.ClassLoader.loadClass(ClassLoader.java:357)... 54更多

  

这是Controller.java文件。这很标准。

import javafx.event.ActionEvent;

public class Controller {

public void TestT(ActionEvent actionEvent) {
        MainProg.main();
    }
}

MainProg.java内容;

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

public class MainProg {
    public static void main() {
        System.setProperty("webdriver.chrome.driver", "/Users/Adam/IdeaProjects/Driver/OSX/chromedriver");
        WebDriver driver = new ChromeDriver();
        driver.get("Http://www.google.com");
    }

}

如果我将TestT函数设置为仅将文本字段的值设置为" Hello World"我没有遇到任何问题。 任何帮助,将不胜感激。 感谢

1 个答案:

答案 0 :(得分:1)

没关系。我是菜鸟我忘记了将chromedriver jar添加到build文件夹中。一切正常。