Protractor Surprise Alert: Oops! jQuery is missing

Troubleshooting jQuery Error

After conducting thorough research, I have come across various code samples to handle expected alert boxes. However, I am facing difficulty in finding a solution for handling random alerts that may or may not appear.

The website I'm working with is particularly challenging as it lacks proper IDs for elements, experiences timeouts, network failures, and other issues.

Out of all the tests I run, 98% of them are successful without encountering any alert box errors. However, the remaining 2% displays an alert box with the message "Error: jQuery not found," causing all subsequent tests to fail due to unexpected alert errors.

My initial query is whether the error is caused by a flaw in my code (see below) or if it originates from the website itself. If the latter is true, could someone provide me with an example of how to handle a potential alert box without disrupting the test? The switchTab() test runs first followed by the setDates() test. The alert box error occurs after switching tabs while the page is loading. Despite attempts to use a deferred promise to manage the alert on catch the error, the failure persists as browser.switchTo().alert() encounters an alert that typically doesn't exist before it can be caught. Any assistance provided would be greatly appreciated.

this.switchTab = function(){
  browser.getAllWindowHandles().then(function(handles){
    browser.switchTo().window(handles[1]);
    browser.sleep(2000);
    var lockBoxTitle = element(by.css('td.title'));
    browser.driver.wait(EC.visibilityOf(lockBoxTitle),5000);
  });
}

this.setDates = function(yesterdayDate){
  browser.sleep(3000);
  //handleAlert();
  startDateTextBox.clear();
  startDateTextBox.sendKeys(yesterdayDate);
  endDateTextBox.clear();
  endDateTextBox.sendKeys(yesterdayDate);
  retrieveBtn.click();
  browser.sleep(5000);
  expect(validateStart.getText()).toEqual(yesterdayDate);
  expect(validateEnd.getText()).toEqual(yesterdayDate);
}

Answer №1

To verify if a popup is currently shown on the screen, and close it if it is:

    var popUpElement = element(by.model(""));
    var closeButton = element(by.model(""));
    popUpElement.isDisplayed().then(function(isCurrentlyDisplayed) {
                        if (isCurrentlyDisplayed) {
                            closeButton.click();
                            console.log("Popup has been closed");
                        } else {
                            console.log("Popup is not currently visible");
                        }
                    });

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

How to manipulate iframe elements using jQuery or JavaScript

Hey there, I have a simple task at hand: I have a webpage running in an iFrame (located in the same folder on my local machine - no need to run it from a server) I am looking to use JavaScript to access elements within this iFrame from the main page. How ...

Restrict the display of items in a unordered list element

Below is my code snippet that limits the number of visible list items in a ul: $wnd.$(el) .find('li:gt(9)') .hide() .end() .append( $wnd.$('<li>+More</li>').click( function(){ $wnd.$(this).nextAl ...

How can I make arrays of a specific length and populate them in JavaScript?

For instance: I have over 100 locations in a single array, each with latitude and longitude values. I need to use these locations with the Google distance matrix API to find nearby shops for my users. The issue is that this API can only handle 25 destinat ...

What is the best way to handle authentication tokens in a Node.js server application?

One challenge I'm facing is calling an API that requires a token to be passed, and this token needs to be refreshed. The main issue is - How and where should I store a token on the server? Some solutions on the internet suggest doing something like th ...

Having trouble accessing the property 'TUT' because it is undefined?

After loading a JSON file using jQuery, I attempted to access specific properties but encountered an undefined error. Despite being able to clearly see the object within the JSON when printed, the issue persists. { "Calculus 1": { "LEC": { "sec ...

Executing several tasks simultaneously with respect to one another, yet in synchronization with the overall program flow

So, I have an async function with a try block that looks something like this: async function functionName() { try { await function1() // all these functions are async await function2() await function3() // more awaits below } catch(err) ...

Find an object within a nested object that meets a specific condition

When given an object structure like the one below: temp = [ {category: 'category1', branch: [{key: 'key A1', value: 'value A1'}, {key: 'key B1', value: 'value B1'}] }, {category: 'category2', ...

Guide on transferring information from .ejs file to .js file?

When sending data to a .ejs file using the res.render() method, how can we pass the same data to a .js file if that .ejs file includes a .js file in a script tag? // Server file snippet app.get('/student/data_structures/mock_test_1', (req, res) = ...

Unable to locate and verify the username and confirm password fields during Python Selenium automation testing

link : URL I am currently engaged in Python Selenium automation testing and have encountered an issue while trying to target the username and confirm password fields. I would greatly appreciate your assistance in writing the correct Python code for these ...

`Active the button once user checks one or more checkboxes using AngularJS`

I'm working on a project where I have checkboxes and a button. I need to figure out how to activate the button when one or more checkboxes are checked using AngularJS. Can anyone provide some guidance? <script src="https://ajax.googleapis.com/aj ...

Testing the NestJS service with a real database comparison

I'm looking to test my Nest service using a real database, rather than just a mock object. While I understand that most unit tests should use mocks, there are times when testing against the actual database is more appropriate. After scouring through ...

Storing and authenticating text in Selenium Webdriver: Best practices for efficient text management

Is there a way to save text from one page and then check if that same text is on another page? ...

Tips for using Firebase JavaScript 2.4.2 and AngularFire 1.2.0 to compare an $id with another $id within a nested collection

Recently, I've been delving into Firebase and despite my solid grasp on it, I still find myself encountering unexpected challenges. My background in SQL has made adapting to NoSQL quite the learning curve. The Goal: My objective is to fetch user pro ...

Why is my Feed2JS RSS feed functional locally but not operational after deployment on GitHub Pages?

I've been using feedtojs.org to display my Medium blog posts on my GitHub Pages website. Strangely enough, it works perfectly fine on my local server but not on the actual domain. The RSS feed is valid. Here's how it appears on my local server: ...

Is there any issue that you can spot with this js / jQuery code?

Presented below is a script that prompts the user to confirm clicking a button based on a system setting. The system setting is saved in a hidden field established from the code-behind. Markup: <asp:HiddenField ID="hfConfirmOnApproval" runat="server" ...

Unable to display text overlay on image in AngularJS

I am experiencing an issue with displaying captions on image modals. .controller('HomeController',['dataProvider','$scope','$location', '$modal', '$log', 'authService', function ...

Utilized JavaScript and CSS class to create a toggleable button

I am attempting to implement a toggle script on a button by using a CSS class. Issue: When I click on button2, it automatically selects button3, which is incorrect. Only one button should be active at a time upon clicking. function togbtn9() { $("#b ...

Properly Adding an External jQuery File in HTML Using jQuery

Seeking assistance as a newcomer to JS and programming in general. Currently working on a website where each page has its own HTML / PHP file, with jQuery and global JS functions included in the footer via a separate includes file "footer.php". Everything ...

Show the GitHub repositories of the user within a React application

Even though I am relatively new to React, I managed to create a GitHub search application. In this app, you can input a user's name in a search box and view their avatar, bio, username, etc. However, I'm facing an issue with fetching their reposi ...

Error: React JS is unable to access the property 'path' because it is undefined

Currently, I am encountering an issue while setting the src of my image in React to this.props.file[0].path. The problem arises because this state has not been set yet, resulting in a TypeError: Cannot read property 'path' of undefined. To provid ...