Selenium:线程“ main” org.openqa.selenium.NoSuchSessionException中的异常:

时间:2018-06-21 03:21:45

标签: java selenium selenium-webdriver geckodriver

package facebook;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class facebook {

    public static void main(String[] args) {
        System.setProperty("webdriver.gecko.driver","C:\\Users\\5558\\eclipse-workspace\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.facebook.com");
        driver.manage().window().maximize();
        driver.findElement(By.xpath(".//*[@id='email']")).sendKeys("abcdefg@gmail.com");
        driver.findElement(By.xpath(".//*[@id='pass']")).sendKeys("selenium123");
        driver.findElement(By.xpath(".//*[@id='u_0_2']")).click();
        driver.quit();
    }
}

我收到Exception in thread "main" org.openqa.selenium.NoSuchSessionException: 的错误消息

1 个答案:

答案 0 :(得分:0)

像这样Difference between @Before, @BeforeClass, @BeforeEach and @BeforeAll

分隔代码

并将驱动程序安装程序设置为@BeforeClass,将driver.quit();设置为@AfterClass。

即使是虚构的也不要在此处发布凭据。