0

so im trying to get an implicit wait on this webdriver script though i am lost because the last three functions fail because there is no element active . though sometimes it works if it loads fast enough.

Error Error: no such element: Unable to locate element: {"method":"css selector","selector":"#pricing-search > pricing-search > div:nth-child(4) > pricing-actions > div > div:nth-child(1) > div > input:nth-child(3)"} (Session info: chrome=73.0.3683.86) (Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.17134 x86_64)

i've tried adding an await and putting it in its own async function. niether have worked

(async function() {
    var title = await driver.getTitle();
    await driver.get('https://store.tcgplayer.com/admin/Pricing');

    await driver.findElement({id: "UserName"}).sendKeys("gameonsylva@icloud.com");
    console.log("oof");

    await driver.findElement({id: "Password" }).sendKeys("1Conjectio!");


    await driver.findElement({css:'#rightSide > div > div > div > div:nth-child(1) > form > input[type="submit"]'}).click();
//////////////////////////fails here////////////////////////////////////////////    

    await driver.wait(function () {
    return driver.findElement({css:'#pricing-search > pricing-search > div:nth-child(4) > pricing-actions > div > div:nth-child(1) > div > input:nth-child(3)'});
    }, 1000 * 60 * 2)
        .then(el => {return console.log(el.click())})
        .catch(err => console.log('Error: ', err.message));

    /*
    driver.wait(function () {
    return driver.findElement({css:'#divImporterUploadContainer > div:nth-child(2) > input[type="file"]'});
    }, 1000 * 60 * 2)
        .then(el => {return console.log(el.sendKeys('C:\\Users\\Game On\\Documents\\Pricing csv Excel Files\\generatedBy_react-csv(1).csv'))})
        .catch(err => console.log('Error: ', err.message));

    driver.wait(function () {
    return driver.findElement({css:'#divImportButtonContainer > input[type="submit"]'});
    }, 1000 * 60 * 2)
        .then(el => {return console.log(el.click())})
        .catch(err => console.log('Error: ', err.message));
    */


    //return driver.quit()
})();```
Cai Martin
  • 17
  • 5
  • do `driver.getTitle`, `driver.get` and all the other functions you `await` all return Promises? – Jaromanda X Apr 05 '19 at 01:39
  • i think so yes. Kinda new to node, js, and Webdriver – Cai Martin Apr 05 '19 at 01:41
  • the error is saying `no such element` ... is there such an element? – Jaromanda X Apr 05 '19 at 01:45
  • on the new page once it loads yes. – Cai Martin Apr 05 '19 at 01:48
  • Using that many levels in your locator is generally not a good idea. Also, avoid using indexes whenever possible. Please post the relevant HTML for the element you are trying to locate and maybe we can come up with a more concise locator. Also, I don't see any waits in your code. I'm guessing that's the issue more than anything. – JeffC Apr 05 '19 at 20:56
  • Possible duplicate of [Selenium WebDriver wait till element is displayed](https://stackoverflow.com/questions/25753014/selenium-webdriver-wait-till-element-is-displayed) – JeffC Apr 05 '19 at 20:56

0 Answers0