简体   繁体   English

无法在Selenium中使用带有Firefox配置文件的PhantomJS驱动程序

[英]Unable to use PhantomJS driver with Firefox profile in Selenium

I try to use a PhantomJS driver for my Selenium tests but I don't succeed to recover my Firefox profile to avoid me login in the website. 我尝试使用PhantomJS驱动程序进行Selenium测试但是我没有成功恢复我的Firefox配置文件以避免我登录网站。 This is my code : 这是我的代码:

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);
        }
    }
}

Can you tell me how to set PhantomJS driver ? 你能告诉我如何设置PhantomJS驱动程序吗?

你无法使用PhantomJS的firefox配置文件,因为你试图使用PhantomJS的firefox配置文件... PhantomJS不是firefox,你怎么认为它会起作用。

Use this code to set the path of the phantomjs driver, Use this and let me know if you facing any issue: 使用此代码设置phantomjs驱动程序的路径,使用此命令,如果您遇到任何问题,请告诉我:

File file = new File("E:\\software and tools\\phantomjs-2.1.1-windows\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");               
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());        

OR 要么

System.setProperty("phantomjs.binary.path", "E:\\software and tools\\phantomjs-2.1.1-windows\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");    
WebDriver driver = new PhantomJSDriver();   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用Selenium为Firefox创建配置文件 - Unable to create profile for firefox using Selenium 无法使用Selenium PhantomJs驱动程序加载整个页面 - Unable to load entire page using Selenium PhantomJs driver Selenium Web-Driver Firefox Profile - 禁用弹出窗口和警报窗口 - Selenium Web-Driver Firefox Profile - Disable popup and alert windows 如何在Selenium Webdriver 3中为Firefox驱动程序设置默认配置文件? - How can I set a default profile for the Firefox driver in Selenium Webdriver 3? Selenium使用什么Firefox驱动程序? - What Firefox Driver does Selenium use? 如何在 Java 中将 Firefox 配置文件和 Firefox 选项与 Selenium 一起使用 - How to use both the Firefox Profile and Firefox options with Selenium in Java 无法通过使用Selenium Webdriver设置Firefox配置文件来下载文件 - Unable to download a file by setting Firefox profile using Selenium Webdriver 无法使用Selenium Java API创建Firefox驱动程序 - Unable to create Firefox driver using Selenium java API Selenium Web驱动程序| Java | 无法在Firefox浏览器窗口之间切换 - Selenium web driver | java | unable to switch between firefox browser windows 无法使用Selenium Web Driver 2.33和Firefox 22打开网页 - Unable to open webpage using selenium web driver 2.33 and firefox 22
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM