运行自动化脚本后就报错invalid session id,已经换个很多次chrome版本了
报错内容:
webdriver.chrome.driver: D:\chromedriver
webdriver.chrome.bin: D:\chromedriver\chromedriver.exe
Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}) on port 29758
Only local connections are allowed
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code
Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}) on port 9515
Only local connections are allowed
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code
Invalid --log-level value
Unable to initialize logging. Exiting
org.openqa.selenium.NoSuchSessionException: invalid session id
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.19042 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 11 milliseconds
Build info: version: '3.3.0', revision: 'b526bd5', time: '2017-03-07 11:21:31 -0800'
System info: host: 'DESKTOP-HPSUNFU', ip: '192.168.100.138', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_77'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{message=unknown error: Chrome failed to start: was killed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location D:\chromedriver\chromedriver.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.19042 x86_64), platform=ANY}]
Session ID: 7b17c986e54cd4c6697d2dafcf5b1f03
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
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:638)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:325)
**
我的代码:**
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
public class Example {
// Mooctest Selenium Example
// <!> Check if selenium-standalone.jar is added to build path.
public static void test(WebDriver driver) {
driver.get("http://114.215.176.95:60503/goodmanage/index.jsp");
driver.manage().window().maximize();
driver.findElement(By.id("userName")).click();
driver.findElement(By.id("userName")).sendKeys("zhangsan");
driver.findElement(By.id("password")).sendKeys("123456");
driver.findElement(By.id("btnLogin")).click();
driver.switchTo().frame(1);
// driver.findElement(By.cssSelector("div:nth-child(1) > div:nth-child(4) > div > span:nth-child(3) > img")).click();
// driver.findElement(By.cssSelector("div:nth-child(1) > div:nth-child(4) > div > img")).click();
// driver.findElement(By.cssSelector("div:nth-child(4) > div:nth-child(2) > div > img")).click();
// driver.findElement(By.linkText("商品添加")).click();
// driver.switchTo().defaultContent();
// driver.switchTo().frame(2);
// driver.findElement(By.id("productName")).click();
// driver.findElement(By.id("productName")).sendKeys("1");
// driver.findElement(By.id("productPrice")).click();
// driver.findElement(By.id("productPrice")).sendKeys("1");
// driver.findElement(By.id("description")).click();
// driver.findElement(By.id("description")).sendKeys("1");
// driver.findElement(By.id("productNumber")).click();
// driver.findElement(By.id("productNumber")).sendKeys("1");
// driver.findElement(By.xpath("/html/body/div/table/tbody/tr[2]/td[2]/div/form/table/tbody/tr[5]/td/input[1]"));
// driver.findElement(By.linkText("商品查询")).click();
// driver.switchTo().defaultContent();
// driver.switchTo().frame(2);
// driver.findElement(By.name("productID")).click();
// driver.findElement(By.name("productID")).sendKeys("1");
// driver.findElement(By.cssSelector(".button")).click();
// driver.switchTo().defaultContent();
// driver.switchTo().frame(0);
// driver.findElement(By.id("HyperLink3")).click();
// TODO Test script
// eg:driver.get("https://www.baidu.com/")
// eg:driver.findElement(By.id("wd"));
}
public static void main(String[] args) {
// Run main function to test your script.
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
// try { test(driver);
// } catch(Exception e) {
// e.printStackTrace();
// }
// finally {
// driver.quit();
// }
}
}