java - 无法在 Selenium 中将 PhantomJS 驱动程序与 Firefox 配置文件一起使用

标签 java selenium firefox webdriver phantomjs

我尝试使用 PhantomJS 驱动程序进行 Selenium 测试,但未能成功恢复我的 Firefox 配置文件以避免登录网站。 这是我的代码:

import static org.junit.Assert.fail;

import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class Stackoverflow {
    private WebDriver driver;
    private String baseUrl;
    private StringBuffer verificationErrors = new StringBuffer();

    @Before
    public void setUp() throws Exception {
        System.setProperty("phantomjs.binary.path", System.getProperty("user.dir") + "/lib/phantomjs-2.1.1-windows/bin/phantomjs.exe");
        DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
        driver = new PhantomJSDriver(capabilities);
        driver.manage().window().maximize();
        baseUrl = "http://stackoverflow.com/";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void testStackoverflow() throws Exception {
        driver.get(baseUrl);
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }
}

你能告诉我如何设置 PhantomJS 驱动程序吗?

最佳答案

您无法将 firefox 配置文件与 PhantomJS 一起使用,因为您正在尝试将 firefox 配置文件与 PhantomJS 一起使用...PhantomJS 不是 firefox,您认为这会如何工作。

关于java - 无法在 Selenium 中将 PhantomJS 驱动程序与 Firefox 配置文件一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38011039/

相关文章:

python - 在以下输入字段上使用 Scrapy 和 send_keys

java - 带有一些 ImageView 的动画包

java - 如何将数据库中的问题存储在 servlet 上并显示在 html 页面上?测验申请

java - 让我自己的 Java 异常(exception)

python - 带有 selenium gird 的 chromedriver - 没有这样的文件或目录

java - 如何在 Javascript 弹出窗口中输入凭据?我们无法传递链接中的凭据

css - Firefox 或 Internet Explorer 中不显示关键帧中的背景图像

javascript - fullcalendar javascript 问题 - 它没有在 IE 中显示事件?

jQuery 选择器语法给 Firefox 发出警告

java - Java 中的 printf 格式化