[Selenium]: Wait Node - Add option to wait for element

Hi @qqilihq,

when UIs are slow I resort to using the find node to search for an element in conjunction with the wait option. Though, that necessitates to remove the added column of the found element.

The use case really just is to wait until an element is present indicating the website has fully loaded.

I’d like to suggest extending the regular wait node by some of the options from the find node like:

  1. Selector Option: CSS, XPath etc.
  2. Wait Options: Duration and check interval

image

image

Best
Mike

1 Like

If my memory serves me well this feature is currently on their roadmap but +1 regardless.

2 Likes

Makes sense. Next update. Word! :slight_smile:

1 Like

PS: It just flashed up in my mind to add an option to invert the result, i.e. wait until an element is not found. This correlates to some degree with the other feature suggestion of mine:

Though, I don’t want to ask for too much … just a suggestion :slight_smile:

:+1: (stay tuned)

-Philipp

1 Like

FYI and maybe for some sort of inspiration. I have put this JavaScript into place to leverage the Web Animations API.

So far my tests were positive but I did not manage to actually retrieve the callback value true, false or error.

/**
 * Add your JavaScript code below:
 */
const callback = arguments[arguments.length - 1]; // last argument is callback

try {
  // Select the element with the id "master"
  const elementMasterOverlay = document.querySelector('#master');

  // Function to handle transition end event for the "width" property
  function handleTransitionEnd(event) {
    // Check if the transitioned property is 'width'
    if (event.propertyName === 'width') {
      // Log the completion of the width transition
      console.log('Width transition finished!', event);

      // Remove the event listener to prevent memory leaks
      elementMasterOverlay.removeEventListener('transitionend', handleTransitionEnd);

      // Resolve the callback with "true" since the width transition is complete
      callback(null, 'true');
    } else {
      // Resolve the callback with "false" if it's not the width transition
      callback(null, 'false');
    }
  }

  // Set up the transitionend event listener specifically for the width property
  if (elementMasterOverlay) {
    elementMasterOverlay.addEventListener('transitionend', (event) => {
      if (event.propertyName === 'width') {
        handleTransitionEnd(event);
      }
    });
  } else {
    // If the element is not found, throw an error to be caught
    throw new Error('Element with ID "master" not found');
  }
} catch (error) {
  // Catch any errors and resolve the callback with "error"
  console.error(error);
  callback(null, 'error');
}

1 Like

Hi Mike,

cannot check the code in detail at the moment, but here’s some advice which might help:

  1. The last entry in the Arguments list called [asyncCallbackMethod] must be enabled.

  2. The callback allows one single argument, so callback(null, true) will not give you the second argument in the result table - if you need more than one result value, use the List or JSON type. You could e.g. do like this and use the JSON return:

    callback({ result: true });
    callback({ result: false  });
    
    // can usually not serialize entire Error object, 
    // so specify your properties manually, e.g. message
    callback({ error: error.message  });
    

Hope that helps!

-Philipp

Thanks for your feedback. asyncCallbackMethod is enabled. The callback is only triggered during either if, else statement or the catch statement. Though, I noticed a warning which, despite me slowing down the scraping to human levels, could cause some issues which led me to submit this feature request:

Throttling navigation to prevent the browser from hanging. See . Command line switch --disable-ipc-flooding-protection can be used to