使用Selenium打开网站时没有萤火虫

时间:2017-09-14 23:24:56

标签: eclipse selenium firebug

我刚刚在Selenium的帮助下开设了Facebook:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class class1 {
    public static void main(String[] args) {

        System.setProperty("webdriver.gecko.driver","C:\\Users\\Hi\\Desktop\\selenium\\geckodriver.exe");

        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.facebook.com");


    }

}

但在那个网站上没有Firebug。当我在没有Selenium的情况下正常打开浏览器时,Firebug图标就在那里。有人可以帮忙吗?

编辑:感谢yong的帮助。借助我在http://toolsqa.com/selenium-webdriver/custom-firefox-profile/

找到的代码,我也找到了解决问题的好方法
ProfilesIni profile = new ProfilesIni();
        FirefoxProfile myProfile = profile.getProfile("default");

        System.setProperty("webdriver.gecko.driver","C:\\Users\\Hi\\Desktop\\selenium\\geckodriver.exe");

        WebDriver driver = new FirefoxDriver(myProfile);
        driver.get("http://www.facebook.com");

1 个答案:

答案 0 :(得分:1)

<强>分析:

Selenium使用默认配置文件打开firefox,此配置文件与您手动打开的配置文件不同。一般来说,默认配置文件不包括你在firefox上使用的插件。

<强>解决方案

  1. 手动创建一个firefox配置文件,默认情况下,新配置文件将包含
    http://kb.mozillazine.org/Creating_a_new_Firefox_profile_on_Windows

  2. 告诉selenium在打开firefox时使用创建的配置文件 How to use custom Firefox Profile with Selenium? (Java) (And pass HTML Authorization Window)