Encountering a JavaScript Error: "e is null" while utilizing assert for checking JavaScript alert text

I encountered a javascript alert in my program that I was able to interact with by reading the text and clicking on the buttons. However, when I tried to verify the alert text using assertequals function, I faced an error. Here is the code snippet:

String test = driver.switchTo().alert().getText();
System.out.println(test);
Assert.assertEquals(test, "You are sharing your report with \"Limited Overall-10000 \".\n\nThis will share your report with \"179\" people. Continue?");

While System.out.println successfully displayed the alert text, I received the following error message when attempting to use assertequals. Interestingly, this issue only occurs for this specific alert, as similar steps work fine for other javascript alerts on the page.

 org.openqa.selenium.WebDriverException: [JavaScript Error: "e is null" {file: "file:///C:/Users/IBM_AD~1/AppData/Local/Temp/anonymous2086351268768311654webdriver-profile/extensions/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4c2dcc0d6cdd2c1d6e4c3cbcbc3c8c1c7cbc0c18ac7cbc9">[email protected]</a>/components/command_processor.js" line: 7716}]     

Answer №1

I encountered a similar error myself.

Upon investigation, I realized that I was mistakenly closing the webdriver prior to dismissing the alert box.

By properly handling the alert by clicking on it first and foremost, followed by closing the driver, the problem was resolved.

Answer №2

Encountered a glitch in Selenium that needs troubleshooting:

(Interestingly, these two bug reports are interconnected.)

Selenium seems to have an issue where terminating the driver while an alert is active results in errors like e is null or similar messages. As pointed out by Lawrence Tierney, it's crucial to ensure that the alert is closed before ending the driver. Your code should incorporate this step regardless of the assert outcome.

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

I'm trying to create a horizontal list using ng-repeat but something isn't quite right. Can anyone help me figure out

Feeling a bit lost after staring at this code for what seems like an eternity. I'm trying to create a horizontal list of 2 image thumbnails within a modal using Angular's ng-repeat. Here's the HTML snippet: <div class="modal-body"> ...

.Internet Explorer text update problem

Encountering a problem specifically in IE (like always). I've managed to narrow down the issue I'm facing to a recursive script responsible for updating a tweet's timestamp. The script functions correctly, identifying all the date/time sta ...

Python and Selenium: Navigating dropdown menu options when an option is not visible

Need help with scraping data from the 2015 municipal elections in Colombia? I'm trying to extract information from this webpage: Visit here So far, I've successfully scraped the number of registered voters ("personas habilitadas") in the municip ...

Eavesdrop on outbound requests on a web page using JavaScript

As I develop a single-page application that integrates a third-party analytics tool (such as Heap, Segment, Mixpanel, etc.), I am looking to actively monitor the outgoing HTTPS requests from my app and take necessary actions, such as logging. I am curious ...

Custom HTML on Joomla causing carousel to vanish

I've encountered an issue with my Joomla website where my carousel images are disappearing. I have a code snippet from W3 Schools for an automatic banner that works perfectly fine when opened in a browser using Notepad++, but when inserted into a cust ...

Enable users to choose either today's date or a future date by implementing AngularJS UI Bootstrap

I am currently utilizing the ui-bootstrap directive for a datepicker. My goal is to restrict the selection of dates to today's date or any future dates. Below is the HTML code snippet for the datepicker: <div class="input-group"> ...

Is there a way to display a loader when an item is selected from a dropdown menu? For example, while data is being fetched from the backend, can we

This is the HTML form division I have created: <div class="col-lg-2 "> <select name="limitCount" id="limitCount" ng-model="limitCount" class="form-control col-md-2 panel-refresh" ...

Is Node.js going to continue to provide support for its previous versions of node modules?

I currently have a website that relies on the following dependencies. While everything is working smoothly at the moment, I can't help but wonder about the future support of these packages by node.js. I've looked into the legacy documentation of ...

Ways to pause and resume the execution of a for loop

I am currently developing a framework for our project. BEFOREMETHOD (it reads the first row using JXl) @BeforeMethod public void Test2() throws BiffException, IOException{ FileInputStream filepath = new FileInputStream("D://Selenium//Project_Stage//A ...

How to Avoid Duplicating Documents in MongoDB?

I'm currently exploring effective methods to avoid saving duplicate documents in MongoDB. Currently, my form captures the user's URL input. The workflow is as follows: Validate if the user's URL is valid (using dns.lookup). If the use ...

Issues arise with User obj's utilization of the Instagram API

After setting up my Instagram developer account, I was able to obtain the client_secret and client_id. Authentication went smoothly for my own user (myusername), and I received an access_token. However, when attempting to utilize this endpoint TOKEN] Fo ...

Implementing Angular to activate the JavaScript 'click' event

I am attempting to initiate an 'onclick' event within an angular controller. <div id="galerie"> <h2>{{main.Page.title()}}</h2> <hr> <div class="row"> <div class="col-sm-4 col-xs-6" ng-repeat= ...

Navigating through multiple pages in Selenium

As a beginner in using Selenium, I have been following a tutorial on web scraping from indeed.com. However, I encountered issues as some elements seem to have changed since the tutorial was created. Specifically, I am stuck at this part: List<WebElement ...

A URL that quickly updates live content from a backend script

As a beginner, I am seeking guidance as to where to start on my journey of learning. I need assistance in creating a script that can efficiently fit within a small URI space and constantly updates itself with information from a server script. My target bro ...

Error message: Can't find Highcharts in (React JS) environment

I have been encountering an error ReferenceError: Highcharts is not defined, and I've been struggling with this issue for a few days now. Can you provide assistance? In my project, I have Dashboard and Chart files where I import the Chart components ...

Generating random indexes for the Answer button to render

How can we ensure that the correct button within the Question component is not always rendered first among the mapped incorrect buttons for each question? Is there a way to randomize the positions of both correct and incorrect answers when displaying them, ...

Utilizing the output of a callback function to execute res.render in a NodeJS application

Currently, I am utilizing oracledb for node in order to retrieve data from the database. Once the data is fetched, my goal is to transmit it to the client side using render() in express JS. Below is an example of the code structure: config.js module.expo ...

Unable to locate AngularJS controller

As my single controller started to become too large, I decided to split it into multiple controllers. However, when I try to navigate to /signup, I encounter an issue where my UserController cannot be found. The error message states: Error: [ng:areq] Argu ...

JavaScript - Issue with For Loop when Finding Symmetric Difference

Here is my solution to a coding challenge on FreeCodeCamp called "Symmetric Difference." I'm puzzled as to why my code is returning 2, 3, 4, 6 instead of the expected 2, 3, 4, 6, 7. function sym(args) { args = Array.from(arguments); var new ...

Penning thoughts while a Jar is in motion

My goal is to create a Jar file that includes data within the Jar which persists between program executions. I am aware of other methods for saving data, but I want the Jar file to be completely self-contained. I have come up with a method that seems to b ...