- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Capturing JavaScript error in Selenium.
We can capture Javascript error in Selenium. This type of error appears at the Console Tab on opening the Developer tools in the browser. This can occur due to some functional issue in the page or due to extra logs which may cause performance issues.
We can handle the Javascript errors with the driver object and manage method.
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.List; import java.util.ArrayList; import org.openqa.selenium.logging.LogEntries; import org.openqa.selenium.logging.LogEntry; import org.openqa.selenium.logging.LogType; import java.util.logging.Level; import java.util.Set; public class JavascrptLogErs{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String u = "https://the−internet.herokuapp.com/javascript_error"; driver.get(u); // maximize browser driver.manage().window().maximize(); // to obtain browser errors Set<String> logtyp = driver.manage().logs().getAvailableLogTypes(); for (String s : logtyp) { System.out.println(logtyp); } LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER); List<LogEntry> lg = logEntries.filter(Level.ALL); for(LogEntry logEntry : lg) { System.out.println(logEntry); } driver.quit(); } }
- Related Articles
- Capturing browser logs with Selenium WebDriver using Java.
- What is Event Capturing in JavaScript?
- Event bubbling vs event capturing in JavaScript?
- What is event Bubbling and capturing in JavaScript?
- TestNG error:- Cannot find class in classpath using Selenium
- JavaScript example for Capturing mouse positions after every given interval
- How to handle SSL certificate error using Selenium WebDriver?
- Unable to locate an element using xpath error in selenium-java
- Explain JavaScript Error Object.
- JavaScript Error message Property
- JavaScript Error name Property
- Named Capturing groups in Java Regex
- What is JavaScript Error Constructor?
- Capturing groups and back references in Java Regex
- Regex capturing groups and back references in Java

Advertisements