簡體   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