1
我需要將我的Java程序從ChromeDriver重寫到PhantomJS。我想我應該啓用PhantomJS而不是ChromeDriver,而不是更多(我是對的?)。我嘗試了幾種方法來做到這一點,但我總是得到NoClassDefFoundError。如何在Selenium中啓用PhantomJS WebDriver?
我能夠ChromeDriver方式:
System.setProperty("webdriver.chrome.driver", CHROMEDRIVER_PATH);
WebDriver driver = new ChromeDriver();
這也是我如何試圖使PhantomJS:
DesiredCapabilities DesireCaps = new DesiredCapabilities();
DesireCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, PHANTOMJSDRIVER_PATH);
WebDriver driver = new PhantomJSDriver(DesireCaps);
第二次嘗試
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, PHANTOMJSDRIVER_PATH);
WebDriver driver = new PhantomJSDriver();
三
File src = new File(PHANTOMJSDRIVER_PATH);
System.setProperty("phantomjs.binary.path", src.getAbsolutePath());
WebDriver driver = new PhantomJSDriver();
謝謝。我在我的pom中擁有detro依賴項1.2.0。現在它工作了! –