【问题标题】:How to write commands into the Firefox console using Selenium WebDriver with Java?如何使用 Selenium WebDriver 和 Java 将命令写入 Firefox 控制台?
【发布时间】:2018-09-23 10:56:45
【问题描述】:

我使用 Selenium Webdriver 打开 Firefox 控制台。

@Test
public void seleniumFirefoxConsole() {
    System.setProperty("webdriver.gecko.driver", "C:\\Users\\FirefoxDriver\\geckodriver.exe");

    FirefoxOptions options = new FirefoxOptions();
    options.addArguments("-console");
    WebDriver driver = new FirefoxDriver(options);

    driver.get("http://www.google.com");
  }

如何在这个控制台中使用这样的 Java 代码编写命令:

console.log("Hello, Firefox console from selenium");

Firefox opened console

【问题讨论】:

  • 为什么要在FF控制台写?

标签: java selenium firefox selenium-webdriver console


【解决方案1】:

使用 JavascriptExecutor 从 selenium 运行 javascript 命令。 只需将以下几行添加到您的测试用例中:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("console.log('Hello, Firefox console from selenium');");

顺便说一句 - 你的用例是什么?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-13
    • 2016-07-18
    • 2020-10-21
    • 2013-04-12
    • 1970-01-01
    • 1970-01-01
    • 2014-08-26
    • 2021-10-01
    相关资源
    最近更新 更多