Selenium javascript is displaying error codes when trying to retrieve console logs

Below is the code snippet I'm using in Selenium with JavaScript. In the final step, I want to retrieve any error codes from the browser console and specifically check for the absence of any 504 error codes on the current page.

driver.get(M_URL)
    .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('checking for a 504 error code in the browser console'));

Thank you in advance!

Answer №1

Learn this method to achieve it:

require('chromedriver');

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);
options.setLoggingPrefs(prefs);

driver = builder
    .forBrowser(wd.Browser.CHROME)
    .setChromeOptions(options)
    .build();

driver
    .get(`file://${path.resolve(__dirname, './page.html')}`)
    .then(() => driver.manage().logs().get(wd.logging.Type.BROWSER))
    .then((logs) => {
        console.log(logs);
    })
    .then(() => driver.quit());

For more information on this topic, visit this link

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What causes Gun.js to generate duplicate messages within a ReactJs environment?

I need assistance with my React application where gun.js is implemented. The issue I am facing is that messages are being duplicated on every render and update. Can someone please review my code and help me figure out what's wrong? Here is the code s ...

What is the best way to retrieve multiple JSON files from a single directory using React?

I am currently working on a React project which includes a folder titled "data" within the src directory. Inside this data folder, there are multiple JSON files that I need to fetch. The issue is that I do not know the names of these JSON files. How can ...

Utilizing a variable in a for loop with Django

I am a beginner in the world of Python and Django framework and I am encountering a small hurdle when trying to assign a variable to my for loop. Within my html file, there are buttons and a list (generated through a loop). For example: Buttons <li&g ...

Filtering pages using the Wordpress API version 2

Is there anyone who can help with the following: I am currently working on building an app in React and using Postman to filter pages. I have set up a Router that is supposed to filter the pages based on which button is clicked. I have experimented with a ...

Using vuetify's v-autocomplete component with the options to select all and clear items

I am trying to incorporate a "Filter by values" feature in my application similar to Excel or spreadsheets. However, I am facing difficulty with implementing the 'Select all' and 'Clear' button in v-autocomplete. <v-col> < ...

Details about the Chrome driver can be found in the console

While running my selenium tests with ChromeDriver, I am seeing this message in the console: Starting ChromeDriver 2.15.322448 (521791b310fec1797c81ea9a20326839860b7d3) on port 15823 Is there a method to hide or prevent this message from appearing in the ...

Highlighting JavaScript code with React Syntax Highlighter exclusively

I've been struggling to highlight Ruby code, but it seems like no matter what I do, it keeps highlighting JavaScript instead. It's frustrating because I can't seem to get it right. import React from "react"; import atom from "node_module ...

Display images from the wikipedia API using asynchronous JavaScript and XML (AJAX

I am attempting to display the images from a Wikipedia article. For example, from To work around the cross-origin policy, I am using a proxy: function imageWp() { var word = 'Appendizitis'; $.ajaxPrefilter( function (options) { if (options ...

The lack of compatibility between the PHP regex function and the inability to convert JavaScript arguments

I developed a basic test for a function that retrieves the video id from a YouTube URL and displays it. Everything is functioning properly as it is, but when I add jQuery code to the mix, I encounter an error message NS_ERROR_XPC_BAD_CONVERT_JS: Could not ...

The 'export '__platform_browser_private__' could not be located within the '@angular/platform-browser' module

I have encountered an issue while developing an angular application. Upon running ng serve, I am receiving the following error in ERROR in ./node_modules/@angular/http/src/backends/xhr_backend.js 204:40-68: "export 'platform_browser_private' w ...

Guide on building a Python Selenium application along with bundled drivers

As I begin my journey with Python and web crawling, I have utilized tools such as Selenium and Beautiful Soup to navigate and parse pages. Now, I am curious about transforming this project into an application or deploying it onto an IIS server (or any ot ...

Storing additional data from extra text boxes into your database can be achieved using AJAX or PHP. Would you

A dynamic text box has been created using Jquery/JavaScript, allowing users to click on an "Add More" button to add additional input boxes for entering data. However, a challenge arises when attempting to store this user-generated data in a database. Assi ...

Encountering an error while trying to launch Chrome with Puppeteer

Currently, I have set up an elastic-beanstalk instance on AWS and am in the process of creating a pdf export feature on a dashboard using Puppeteer. Although I have successfully tested the application locally, I encountered an error when attempting to run ...

Finding elements using class name with two underscores

When I attempt to locate an element by its class name, I encounter an issue due to the presence of double underscores in the class name which results in a "no such element" error. The div-element that needs to be selected is as follows: <div class="re ...

Adding a break in a CardHeader element subtitle in MaterialUI using ReactJS

I have been working with older Material UI components (Version 0.20.1). Below is an excerpt of my code: return( <> <Card> <CardHeader actAsExpander={true} showExpandableButton={true} title = {user.name} ...

How can you enable Location and Notifications in Chrome's incognito mode using Python and Selenium?

I am trying to enable notifications and location permissions in Chrome's incognito mode using Selenium. Below is the code I am using: import selenium from selenium.webdriver.chrome.options import Options from selenium import webdriver option = Option ...

Utilizing Three.js to import models directly from a database

Currently, I have a MySQL database containing FBX models. The client-side of my application is able to read these models from the database. However, the model data is stored in a JavaScript variable. How can I utilize THREE.FBXLoader() to load the model da ...

Styling the <Autocomplete/> component in Material UI with React to achieve rounded corners

Google's search bar has always been a favorite of mine, with its rounded corners and generous text padding. https://i.stack.imgur.com/UbKrr.png I'm attempting to replicate this aesthetic using Material UI's <Autocomplete/> component ...

Unravel JSON data to become PHP variables

When using angularJS ajax, I send data to a PHP file like this: { username: "someusername", password: "somepassword" } In the past, I used the following method to send data: var vars = "username="+fn+"&password="+ln; However, since angular sends da ...

d3: It appears that my routes are replicating themselves, and I am unable to ascertain the cause

I've been diving deep into D3, studying the works of Mike Bostock and other experts in the field. I'm also going through Scott Murray's book on Interactive Data Visualization specifically focusing on D3. At the moment, my project involves c ...