Opting to monitor element visibility over relying solely on page load with Neustar WPM

I need help with writing a Neustar WPM script to time the button click until an overlay appears. Here is what my current script looks like:

var webDriver = test.openBrowser();
var selenium = webDriver.getSelenium();

webDriver.get('https://www.mywebsite.com');
selenium.waitForPageToLoad(30000);

// Start logging HTTP traffic and timings
test.beginTransaction();    

test.beginStep("Open SignUp");
selenium.click("link=Sign Up");
selenium.waitForElementPresent("name=nextStep");
test.endStep();

test.endTransaction(); 

I am encountering an issue where the click function does not return immediately and waits for the entire page to load including the overlay. However, I want it to stop as soon as the desired element is visible. How can I modify the script so that selenium.click returns immediately instead of waiting for the entire page to load?

Answer №1

If you're looking to enhance your Java skills, give this Java method a shot:

public WebElement waitForVisibilityOfElementLocatedBy(final By locator) {
        return waitFor(visibilityOfElementLocated(locator));
    }

public static ExpectedCondition<WebElement> visibilityOfElementLocated(final By locator) {
    return new ExpectedCondition<WebElement>() {
        public WebElement apply(WebDriver driver) {
            try {
                return ExpectedConditions.elementIfVisible(ExpectedConditions.findElement(locator, driver));
            } catch (StaleElementReferenceException var2) {
                return null;
            }
        }

        public String toString() {
            return "visibility of element located by " + locator;
        }
    };
}

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

hybrid application combining AngularJS with Angular 17 and above versions

I have been attempting to set up a hybrid environment with both AngularJS and Angular 1.7+ running side by side. I diligently followed all the guidelines and even created a custom webpack configuration to bundle my AngularJS and Angular files together. The ...

Determine the quantity of characters available in a contenteditable field

I have implemented a directive that allows me to input editable content inside a tag Recently, I made modifications to include a character counter feature. However, I noticed that when I add line breaks, the character count increases erroneously. https: ...

Rearrange the text next to the Checkbox using Bootstrap

I'm having trouble aligning the "Default checkbox" text next to the checkbox itself checkbox This is what I've attempted so far <div class="col-2"> <label for="Desc" class="col-sm col-form-label">D ...

Following a successful ajax response, the functionality of the JavaScript ceases to operate

Once an Ajax request is successfully sent, the jquery.hover() function no longer works with the new content on the page. Is there a method to refresh the script without reloading the entire div through another ajax request, in order to make it functional ...

Is there a way to dynamically insert my own <divs> into a container?

I've been doing a lot of research on this issue, but I haven't come across any solutions that have been helpful so far. The problem I'm facing is that I have a div with an id that is supposed to act as a container (#cont_seguim). On the rig ...

What are the steps to switch the dropdown values?

I am facing an issue with swapping values in two dropdowns. The scenario is that I have a dropdown with minimal values and another one with maximum values. If a value selected in the first dropdown is greater than the value in the second dropdown, they nee ...

Is it permissible to enclose useEffect hooks within an IIFE?

Currently, I am dealing with a project that is rife with anti-patterns. One issue that has caught my attention is the use of Immediately Invoked Function Expressions (IIFE) around multiple useEffect hooks. Here is a snippet of the code in question: conditi ...

Switching the focus of an input field using JavaScript

I am attempting to implement a button that will shift the focus of an input field. My approach involves using v-bind:autofocus and updating the values of box1 and box2. <input type="text" placeholder="box1" v-bind:autofocus="box1"> <input type= ...

The functionality of Selenium grid is dependent on having chromedriver locally installed

To set up my selenium grid and hub, I used the following commands: hub: java -jar selenium-server-standalone-3.14.0.jar -role hub node: java -jar selenium-server-standalone-3.14.0.jar -role node -hub http://localhost:4444/grid/register After checking t ...

Error: Unable to access the 'prototype' property of an undefined object (inherits_browser.js)

After updating our app to a newer version of create-react-app, we started encountering the following error: https://i.sstatic.net/ILdsl.png This error seems to be related to inherits_browser.js, which is likely from an npm module that we are unable to id ...

Electron Developer: "An issue has occurred within the primary process - Callback function missing"

My Electron application runs smoothly when launched from the command line with npm start. However, I am now looking to distribute the application as user-friendly installers for Mac/Windows/Linux. To achieve this, I am utilizing Electron-Builder for packag ...

Ways to incorporate a dynamic value into a chart created with chart.js?

I want to create a doughnut chart representing the number of individuals who have tested positive for Coronavirus and the number of deaths related to it. How can I transfer the same data from the top container into the chart? The confirmedCases and deaths ...

before sending the url with fetch(url), it is adjusted

My front end code is currently fetching a URL from a local node.js server using the following snippet: fetch('http://localhost:3000/search/house') .then(.... Upon checking what is being sent to the server (via the network tab in Firefox dev ...

How can I fetch data from a PHP file using an Ajax request?

Recently, I delved into the realm of Ajax requests and devised this script: function ajax_post(){ // Initiating XMLHttpRequest object var xmlhttp = new XMLHttpRequest(); // Setting up necessary variables for sending to PHP file var url = " ...

Storing a token in NodeJS using JavaScript

We currently have a mobile single-page application built using HTML/CSS/NodeJS. The functionality of this app requires numerous API calls, all of which require a bearer token for authorization purposes. This bearer token is simply a string value that we ge ...

Exploring nested optgroup functionality in React.js

Within my code, I am utilizing a nested optgroup: <select> <optgroup label="A"> <optgroup label="B"> <option>C</option> <option>D</option> <option>G</option> </optg ...

Exploring the process of building a JavaScript function inside a JSON object using Gson

Can Gson generate JSON that includes a JavaScript function without a key nested within? { autosave: { save( editor ) { return editor.saveData( editor.id, editor.getData() ); }, waitingTime: 2000 } Appreciate any hel ...

Creating a streamlined process for developing a library that is compatible with various languages and platforms

Greetings! I am facing the challenge of writing 4 libraries in 3 different languages for 2 platforms to make my PCB module compatible with both Raspberry Pi and Arduino. These libraries mainly consist of bit manipulation functions, which will then be integ ...

Show the user a number rounded to two decimal places in JavaScript without altering its original precise value

Take for instance this decimal value: let myDecimal = 117.049701384; I need to display 117.05 to the user without altering the original precise value above. I am aiming to replicate Excel's behavior with decimals, showing a number with two decimal ...

Unexpected behavior observed with excessively large string arrays

I am facing an issue with my array containing 58112 words. Whenever I try to check if a word is in the list, it always returns false, except for the first word. While I cannot share my entire code due to its length, here are the key details: isWord("a ...