【问题标题】:No firebug when open a website with Selenium使用 Selenium 打开网站时没有萤火虫
【发布时间】:2018-02-24 01:19:44
【问题描述】:

我刚刚在 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");

【问题讨论】:

标签: eclipse selenium firebug


【解决方案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)

【讨论】:

  • 谢谢你!我有一个问题:我意识到,可以打开同一页面的第二个浏览器(但没有 Selenium)并使用 Firebug 获取元素的 id 或 className 并将其添加到代码中。你会建议这种方式还是有问题?
  • 不行,selenium在启动浏览器的时候需要一开始就获得浏览器的控制权,你启动的浏览器没有selenium,selenium没有权力控制它。要详细了解 Selenium 服务器/Selenium Client API/Webdriver.exe/真实浏览器之间的关系,了解您的脚本如何与浏览器通信的过程。它将帮助您更好地了解selenium和webdriver的背景以及您使用selenium的道路
  • 只有一条评论。您的解决方案很好,但我认为此视频的此解决方案更好:youtube.com/watch?v=I6AaCvEgNmo 使用 tis 解决方案,您可以使用“默认”Firefox,包括 Firebug
猜你喜欢
  • 2011-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-14
  • 2011-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多