在Java程序中,我使用了 chromedriver 之类的网络驱动程序来编写一段代码来设置属性,我已经管理了Cookie,页面加载,最小化和超时等属性,以打开特定网站,例如( www.edureka.com)与硒工具。
这是我的代码
package co.sample.selenium.webdriver.demo;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class SampleDay
{
WebDriver driver;
public void invokeBrowser()
{
try {
System.setProperty("webdriver.chrome.driver","C:\\Users\\zenith\\Downloads\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.get("http://www.edureka.com");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
SampleDay myobj1=new SampleDay();
myobj1.invokeBrowser();
}
}
当我尝试执行程序时,我感觉不到EXception
org.openqa.selenium.NoSuchSessionException: invalid session id
(Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 17 milliseconds
Build info: version: '3.0.0', revision: '350cf60', time: '2016-10-13 10:48:16 -0700'
System info: host: 'zenith-PC', ip: '192.168.1.8', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{message=unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Users\zenith\AppData\Local\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 6.1.7601 SP1 x86_64), platform=ANY}]
Session ID: eb6921f3cf29b2b63db8b0c7372f9a50
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions.deleteAllCookies(RemoteWebDriver.java:730)
at co.sample.selenium.webdriver.demo.SampleDay.invokeBrowser(SampleDay.java:17)
at co.sample.selenium.webdriver.demo.SampleDay.main(SampleDay.java:33)
我对硒很陌生,请帮助我。 谢谢。