Home  >  Article  >  Java  >  Capturing browser logs using Java and Selenium WebDriver

Capturing browser logs using Java and Selenium WebDriver

王林
王林forward
2023-09-04 23:53:011394browse

We can use Selenium to capture browser logs. We need to cast RemoteWebDriver to driver and initialize it. Next, we need to use the setLogLevel method. You need to add the import org.openqa.selenium.remote.RemoteWebDriver statement to your code to use RemoteWebDriver.

Syntax

((RemoteWebDriver) driver).setLogLevel(Level.INFO);

Example

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.RemoteWebDriver
import java.util.logging.Level;
public class BrwLogs{
   public static void main(String[] args) {
      System.setProperty("webdriver.chrome.driver",
      "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      // Enable logging with setLogLevel method
      ((RemoteWebDriver) driver).setLogLevel(Level.INFO);
      driver.get("https://www.tutorialspoint.com/index.htm");
      //identify element
      driver.findElement(By.id("gsc−i−id1")).sendKeys("Selenium");
      driver.quit();
   }
}

Output

使用Java和Selenium WebDriver捕获浏览器日志

The above is the detailed content of Capturing browser logs using Java and Selenium WebDriver. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete