เราสามารถจับข้อผิดพลาด Javascript ใน Selenium ข้อผิดพลาดประเภทนี้ปรากฏที่ คอนโซล แท็บในการเปิด นักพัฒนา เครื่องมือในเบราว์เซอร์ สิ่งนี้อาจเกิดขึ้นเนื่องจากปัญหาการทำงานบางอย่างในหน้าเว็บหรือเนื่องจากบันทึกพิเศษซึ่งอาจทำให้เกิดปัญหาด้านประสิทธิภาพ

เราสามารถจัดการกับข้อผิดพลาด Javascript ด้วยวัตถุไดรเวอร์และวิธีจัดการ
ตัวอย่าง
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();
}
}