Gabe D. Gabe D. - 8 months ago 34
Node.js Question

How to run selenium webdriver code once element is present

Everything I've seen over the past month of looking is outdated.
Here's my problem, I traverse through about 5 different pages on one website before I get to the data I need. I can't fire off a

as the url stays the same for all 5 different pages.

is asynchronous it runs the code before the element is present. I realize I could use a timeout, but i'm running this code 100's of times so a timeout won't work.

Everyone online says to do this, but it's outdated and doesn't work:

driver.findElement(By.css('#gridsortlink')).then(function(webElement) {
.then(function(found) { console.log(found); });

If you do know how to do this that'd be great as I've been looking for a month now for the solution.


Your tried attempt looks incorrect, you should try as below :-

var webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until;

driver.wait(until.elementLocated(By.css('#gridsortlink')), 5 * 1000).then(function(found) {