ArryList<yang> 2021-10-27 11:40 采纳率: 0%
浏览 269

Java+selenium运行后报org.openqa.selenium.NoSuchSessionException: invalid session id

运行自动化脚本后就报错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(); 
//            }
    }

}

  • 写回答

1条回答 默认 最新

  • 普通网友 2021-10-27 11:52
    关注

    你应该是session处理不对

    评论

报告相同问题?

问题事件

  • 创建了问题 10月27日

悬赏问题

  • ¥15 12864只亮屏 不显示汉字
  • ¥20 三极管1000倍放大电路
  • ¥15 vscode报错如何解决
  • ¥15 前端vue CryptoJS Aes CBC加密后端java解密
  • ¥15 python随机森林对两个excel表格读取,shap报错
  • ¥15 基于STM32心率血氧监测(OLED显示)相关代码运行成功后烧录成功OLED显示屏不显示的原因是什么
  • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。
  • ¥30 求给定范围的全体素数p的(p-2)/p的连乘积值
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令