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.
((RemoteWebDriver) driver).setLogLevel(Level.INFO);
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(); } }
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!