Fetch console logs error code selenium js

  • The following is my code in selenium JS, at the last step, I want to fetch the error code from the browser console, I need to check, there shouldn't be any 504 error code in the browser console for the current page.

        .then(() => {
            return driver.findElement(By.xpath('//input[@id="UserName"]'))
                .then(el => el.sendKeys(USERNAME));
        .then(() => {
            return driver.findElement(By.xpath('//input[@id="Password"]'))
                .then(el => el.sendKeys(PASSWORD));
        .then(() => {
            return driver.findElement(By.xpath('//button[text()="Login"]'))
                .then(el => el.click());
        .then(() => {
        return driver.findElement(By.xpath('//h3[text()[contains(.,"Publisher")]]')).click()
            .then(() => log('Publisher page is rendered'));
        .then(() => log('check 504 error code in browser console'));

    Thanks in Advance!

  • Here is how can you do it

    const path = require('path');
    const wd = require('selenium-webdriver');
    const chrome = require('selenium-webdriver/chrome');
    var builder = new wd.Builder();
    var options = new chrome.Options();
    var prefs = new wd.logging.Preferences();
    var driver;
    prefs.setLevel(wd.logging.Type.BROWSER, wd.logging.Level.ALL);
    driver = builder
        .get(`file://${path.resolve(__dirname, './page.html')}`)
        .then(() => driver.manage().logs().get(wd.logging.Type.BROWSER))
        .then((logs) => {
        .then(() => driver.quit());

Suggested Topics