Home > Java > javaTutorial > body text

Capturing browser logs using Java and Selenium WebDriver

王林
Release: 2023-09-04 23:53:01
forward
1410 people have browsed it

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);
Copy after login

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();
   }
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template