Java Firefox webdriver未启动,驱动程序显示为空

Java Firefox webdriver未启动,驱动程序显示为空,java,selenium-webdriver,selenium-firefoxdriver,Java,Selenium Webdriver,Selenium Firefoxdriver,我正在尝试使用46.0.1版和webdriver 2.53.0版在Firefox中运行测试,但是当我运行测试时,我看到Firefox很快启动,然后关闭。我有其他所有的浏览器可以使用,我不知道我在这里遗漏了什么 driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get(URL); FirstPage FirstPage=PageFactory.initElements(驱动程序,FirstPage.

我正在尝试使用46.0.1版和webdriver 2.53.0版在Firefox中运行测试,但是当我运行测试时,我看到Firefox很快启动,然后关闭。我有其他所有的浏览器可以使用,我不知道我在这里遗漏了什么

driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get(URL);
FirstPage FirstPage=PageFactory.initElements(驱动程序,FirstPage.class); 首页

  @BeforeClass
    public static void setUp() {
        System.out.println("****************");
        System.out.println("launching Browser");
driver = new FirefoxDriver();
    driver.get("url");

   @Test
    public void testPageTitleInBrowser() {
主页已更改为首页

                 .logIn(username, password)
                .clickHolidayLink()
                .completeHolidayFormAndSubmit("12/05/2016");


    }

@AfterClass
    public static void tearDown() {
        if (driver != null) {
            System.out.println("Closing browser");
            driver.quit();
        }
    }

添加
线程睡眠(3000)
driver.quit()之前或删除
驱动程序。退出()并查看发生了什么。由于您在测试中没有做太多工作,它可能运行正常。

由于上述代码片段中没有编写测试用例,firefox驱动程序将在
@BeforeClass
中打开,并作为条件
驱动程序!=在
@AfterClass
中满足null
,firefox即将关闭。根据您的代码,这是预期的行为。

我遇到了类似的问题。Firefox将打开然后关闭,甚至不导航到指定的URL。升级到最新的selenium(2.53)修复了该问题

还有一个例子是,即使升级后的系统也无法工作。这是因为我的组织安装了一些插件


暂时重命名Firefox安装位置中存在的“分发”目录,看看是否有效。例如:
C:\ProgramFiles(x86)\Mozilla Firefox\
/usr/lib/Firefox/
这对我很有效

你能粘贴完整的代码吗?这就是我的@BeforeClass中的所有内容。你还需要什么?MainPage MainPage=PageFactory.initElements(驱动程序,MainPage.class);主页//。登录(“用户名”、“密码”)。单击HolidayLink()。完成HolidayForm并提交(“12/05/2016”);这是我的测试基于提供的信息,这将被关闭,因为“无法复制”。通读一下。你有没有遇到任何异常,如果有,请粘贴它。没有,没有异常,它只是挂起并且没有超时。我确实看到Firefox打开了,但它马上就关闭了。就证据而言,我真的没有太多可以提供的了。我删除了driver.quit,但仍然立即启动和关闭。嗯,我要说明goI似乎找不到分发文件夹。它似乎没有被隐藏,也不在您提到的任何一个区域。我想他们已经从Firefox的较新版本中删除了分发文件夹哪个版本的selenium webdriver?你在哪个操作系统上运行这个?你能粘贴Firefox安装目录树结构(在windows上使用
tree/A
在linux上使用
find
)吗?我使用的是2.53.0 selenium。我在Windows8上运行。这是Firefox目录C:\Program Files(x86)\Mozilla Firefox(这是您想要的吗?),因此调试该问题时,您确认驱动程序为空。但我在intelliJ的VM选项中添加了-Dwebdriver.firefox.bin=“C:\Program Files(x86)\Mozilla firefox\firefox.exe”。我在主要问题中更新了一个测试用例。你能给我添加到主要问题中的MainPage类吗?这段代码是试图执行登录操作还是在启动后退出。此外,此代码是否与其他浏览器配合使用?它将在加载页面后执行登录。是的,它适用于其他浏览器。当我使用chrome或IE时,驱动程序不是空的,但当我使用firefox时,驱动程序似乎显示为空。此外,司机从未退出它只是继续运行,直到我按下停止。看起来firefox会启动一秒钟,然后马上关闭。
import com.google.common.annotations.VisibleForTesting;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import static Internal.BaseTest.driver;


public class FirstPage {


    @VisibleForTesting
    @FindBy(id = "ctl00_MCPH_MainLogin_UserNameTextBox")
    WebElement usernameInput;

    @VisibleForTesting
    @FindBy(id = "ctl00_MCPH_MainLogin_PasswordTextBox")
    WebElement passwordInput;

    @VisibleForTesting
    @FindBy(id = "ctl00_MCPH_MainLogin_LoginButton")
    WebElement loginButton;


    public BookAHoliday logIn(String username, String password){
        usernameInput.sendKeys(username);
        passwordInput.sendKeys(password);
        loginButton.click();
        return PageFactory.initElements(driver, BookAHoliday.class);
    }
}