gpt4 book ai didi

java - org.openqa.selenium.NoSuchSessionException : Session ID is null. 调用 quit() 后使用 WebDriver?通过 Java 使用 ChromeDriver Selenium 时出错

转载 作者:行者123 更新时间:2023-12-01 19:42:41 26 4
gpt4 key购买 nike

有人可以帮忙解决以下问题吗,我在 eclipse 上设置了一个 Maven 项目,每次运行测试时,它在 chrome 上运行良好,但在 junit 控制台上出现以下错误:

org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '4.0.0-alpha-3', revision: '8c567de6dc'
System info: host: '04081W10', ip: '10.50.47.210', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:128)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:576)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:327)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:375)
at org.openqa.selenium.By$ById.findElement(By.java:196)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:319)
at Scenarios.NormanNrasProject.InternalNameReserve1YearTest.InternalNameReserve90DaysTest(InternalNameReserve1YearTest.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)

这是我的代码:

    System.setProperty("webdriver.chrome.driver", "C:\\Users\\nrapoo\\Desktop\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
WebDriverWait wait=new WebDriverWait(driver, 20);
driver.get("http://cedd-wb/enter.htm");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@id=\"username\"]")).sendKeys("seden");
driver.findElement(By.xpath("//*[@id=\"pword\"]")).sendKeys("hello1");
driver.findElement(By.xpath("//*[@id=\"login_form\"]/div[3]/button")).click();
driver.findElement(By.xpath("//*[@id=\'menuDropdown-enq\']")).click();
Thread.sleep(300L);
driver.findElement(By.xpath("//ul[@class='list-unstyled di-block m-y-10']//a[contains(text(),'People')]")).click();
driver.switchTo().frame("browsePeopleFrame");
Thread.sleep(500L);
driver.findElement(By.xpath("//*[@id='quickselect']")).sendKeys("ATNS");
Thread.sleep(500L);
driver.findElement(By.xpath("//*[@id=\"peopleSelectFormBean\"]/div[2]/div[1]/div/div/div/span[2]/button/span")).click();
driver.switchTo().defaultContent();
WebElement namingwait;
namingwait = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//ul[@id='categories-tabs']//a[contains(text(),'Naming')]")));
namingwait.click();
driver.switchTo().defaultContent();
WebElement reservedname;
reservedname = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"category-114\"]/div[1]/a[1]")));
reservedname.click();
Thread.sleep(900L);
driver.findElement(By.xpath("//*[@id=\"content\"]/section[3]/div/article/header/ul/li/a")).click();
char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray();
StringBuilder sb = new StringBuilder();
Random random = new Random();
for (int i = 0; i < 8; i++) {
char c = chars[random.nextInt(chars.length)];
sb.append(c);
String name = sb.substring(0, 1).toUpperCase() + sb.substring(1);
driver.findElement(By.id("newName")).sendKeys("Cote" + name + name + name + "jay");
driver.findElement(By.xpath("//*[@id=\"proposedNameForm\"]/div/div/div[1]/span/button")).click();
driver.findElement(By.xpath("//textarea[@id='meaning']")).sendKeys("MEANING");
driver.findElement(By.xpath("//*[@id=\"reservationType2\"]")).click();

Thread.sleep(900L);
driver.findElement(By.xpath("//*[@id=\"nav-footer\"]/div/ul/li[1]/button")).click();
driver.findElement(By.xpath("//button[@name='_target10']")).click();
driver.findElement(By.xpath("//button[@name='_finish']")).click();
driver.findElement(By.xpath("//a[contains(text(),'Return to Enquire Name Reservations')]")).click();
Thread.sleep(900L);
driver.quit();

最佳答案

我在此代码块中看到的唯一问题是,您仅切换到 frame 一次:

driver.switchTo().frame("browsePeopleFrame");

您已切换到 defaultContent() 两次,如下所示:

driver.switchTo().defaultContent();
WebElement namingwait;
namingwait = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//ul[@id='categories-tabs']//a[contains(text(),'Naming')]")));
namingwait.click();
driver.switchTo().defaultContent();

您需要调整帧切换。

但是,Selenium Java 客户端 v4.0.0-alpha-3 是 alpha 版本,不应用于生产测试

此外,请确保:

  • ChromeDriver 已更新为当前 ChromeDriver v79.0.3945.36级别。
  • Chrome 已更新至当前 Chrome 版本 79.0 级别。 (根据 ChromeDriver v79.0 release notes )
  • 通过IDE清理您的项目工作区,并仅使用所需的依赖项重建项目。
  • 如果您的基本网络客户端版本太旧,请通过 Revo Uninstaller 卸载它并安装最新的 GA 和已发布版本的Web 客户端

关于java - org.openqa.selenium.NoSuchSessionException : Session ID is null. 调用 quit() 后使用 WebDriver?通过 Java 使用 ChromeDriver Selenium 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59159356/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com