使用 Selenium 從 Firefox 獲取 console.log 輸出。
我們能夠透過 Selenium 從 Firefox 中獲取 console.log 輸出。這是用 setProperty 方法完成的。FirefoxDriver.SystemProperty.BROWSER_LOGFILE 和將日誌記錄在其中的檔案路徑作為引數傳遞給該方法。
語法
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "FFLogs.txt");
重新整理專案資料夾後,我們將獲得要捕獲其中的日誌的 FFLogs.txt 檔案。
示例
程式碼實現。
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.logging.LogType;
public class FirefoxLogs{
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe");
// set the System Property to BROWSER_LOGFILE and path of log file
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "FFLogs.txt");
WebDriver driver = new FirefoxDriver();
driver.get("https://tutorialspoint.tw/tutor_connect/index.php");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
// identify element
driver.findElement(By.id("txtSearchText")).sendKeys("Selenium");
driver.quit();
}
}輸出
在專案資料夾中建立一個名為 FFLogs.txt 的日誌檔案。

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP