繁体   English   中英

如何使用带有Java的Selenium WebDriver将命令写入Firefox控制台?

[英]How to write commands into the Firefox console using Selenium WebDriver with Java?

我使用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打开控制台

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

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

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM