Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将错误获取为";无此会话例外“;尝试通过FirefoxProfile打开网站时_Java_Selenium_Firefox_Selenium Webdriver_Geckodriver - Fatal编程技术网

Java 将错误获取为";无此会话例外“;尝试通过FirefoxProfile打开网站时

Java 将错误获取为";无此会话例外“;尝试通过FirefoxProfile打开网站时,java,selenium,firefox,selenium-webdriver,geckodriver,Java,Selenium,Firefox,Selenium Webdriver,Geckodriver,我正在运行下面的代码,打开一个URL。然而,我得到的错误是“NoSuchSessionException”。请建议 是因为我正在使用以下版本 Selenium-->3.12.0、Firefox安装程序50.0和geckodriver-v0.21.0-win64 您可以使用FireFoxProfile类和FirefoxOptions类来设置配置文件 FirefoxOptions options = new FirefoxOptions(); FirefoxProfile firefoxProfi

我正在运行下面的代码,打开一个URL。然而,我得到的错误是“NoSuchSessionException”。请建议

是因为我正在使用以下版本

Selenium-->3.12.0、Firefox安装程序50.0和geckodriver-v0.21.0-win64


您可以使用FireFoxProfile类和FirefoxOptions类来设置配置文件

FirefoxOptions options = new FirefoxOptions(); 
FirefoxProfile firefoxProfile  = new FirefoxProfile(pathToProfile);
options.setProfile(firefoxProfile);

使用现有Firefox配置文件访问Web应用程序有两种方法,如下所示:

  • 使用
    DesiredCapabilities()
    FirefoxOptions()

  • 使用
    FirefoxOptions()

注意:在触发测试之前,确保您已经创建了一个Firefox配置文件,名为Abhi_Selenium


更新 由于您仍将异常视为没有此类会话,请执行以下升级/清理步骤:

  • 将JDK升级到最新级别
  • 将硒升级到当前水平
  • 将GeckoDriver升级至标高
  • 确保GeckoDriver位于指定位置
  • 确保GeckoDriver对非root用户具有可执行权限
  • 将Firefox版本升级到Firefox v61.0.1级别
  • 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
  • (仅限Windows OS)在执行测试套件之前和之后,使用该工具清除所有操作系统杂务
  • (仅限LinuxOS)在执行测试套件之前和之后
  • 如果您的基本Web客户端版本太旧,请通过卸载它并安装最新的GA和Web客户端发布版本
  • 重新启动系统
  • 以非root用户身份执行
    测试
  • 始终在
    tearDown(){}
    方法中调用
    driver.quit()
    ,以优雅地关闭和销毁Web驱动程序和Web客户端实例

第一次查看时,firefox.exe的路径丢失。这是我的设置:

public class foo{
    private static WebDriver driver;

@BeforeClass
    public static void setUpClass() {
        FirefoxOptions options = new FirefoxOptions();
        ProfilesIni allProfiles = new ProfilesIni();         
        FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");
        options.setProfile(selenium_profile);
        options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
        System.setProperty("webdriver.gecko.driver", "C:\\Users\\pburgr\\Desktop\\geckodriver-v0.20.0-win64\\geckodriver.exe");
        driver = new FirefoxDriver(options);
        driver.manage().window().maximize();}

// @Before, @After, @AfterClass and @Test

}

我猜你的FireFoxProfile有问题。尝试不使用个人资料。谢谢的副本。。谢谢你的回复。。请告诉我您使用的Firefox/Selenium和Geckodriver的版本。。我试着使用你的建议,但我仍然得到“没有这样的会议”的例外。。Thanks@AbhishekDingre查看我的答案更新并让我知道状态谢谢!!这是兼容性问题。。使用我的firefox、geckodriver和seleniumversions@AbhishekDingre很高兴能帮助你!!!如果这个/任何答案对你有帮助,为了未来读者的利益,请向上投票。谢谢你的帮助@阿披实丁格尔:好吧,如果这行得通的话,你只需点击“向下投票”按钮下方的复选标记就可以接受这个答案。
public class FirefoxProfile_dc_opt {

    public static void main(String[] args) {

        System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
        ProfilesIni profile = new ProfilesIni();
        FirefoxProfile testprofile = profile.getProfile("Abhi_Selenium");
        DesiredCapabilities dc = DesiredCapabilities.firefox();
        dc.setCapability(FirefoxDriver.PROFILE, testprofile);
        FirefoxOptions opt = new FirefoxOptions();
        opt.merge(dc);
        WebDriver driver =  new FirefoxDriver(opt);
        driver.get("https://www.google.com");
    }
}
public class FirefoxProfile_opt {

    public static void main(String[] args) {

        System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
        ProfilesIni profile = new ProfilesIni();
        FirefoxProfile testprofile = profile.getProfile("Abhi_Selenium");
        FirefoxOptions opt = new FirefoxOptions();
        opt.setProfile(testprofile);
        WebDriver driver =  new FirefoxDriver(opt);
        driver.get("https://www.google.com");
    }
}
public class foo{
    private static WebDriver driver;

@BeforeClass
    public static void setUpClass() {
        FirefoxOptions options = new FirefoxOptions();
        ProfilesIni allProfiles = new ProfilesIni();         
        FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");
        options.setProfile(selenium_profile);
        options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
        System.setProperty("webdriver.gecko.driver", "C:\\Users\\pburgr\\Desktop\\geckodriver-v0.20.0-win64\\geckodriver.exe");
        driver = new FirefoxDriver(options);
        driver.manage().window().maximize();}

// @Before, @After, @AfterClass and @Test

}