S
S
Sland Show2020-06-06 15:31:23
JavaScript
Sland Show, 2020-06-06 15:31:23

How to search for the xpath of an element in a new opened window?

I have a simple node.js program that goes to tinder and tries to login with facebook.

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

 let driver = await new Builder()
        .forBrowser("chrome")
        .build();
 // Google tinder
        await driver.get("https://tinder.com/?lang=ru");

        // Accept privacy polices
        let policyBtnPath = "//*[@id=\"content\"]/div/div[2]/div/div/div[1]/button";
        await driver.findElement(By.xpath(policyBtnPath))
            .click();

        // Waiting for login button and bush it
        await sleep(3000);
        let loginBtnPath = "//*[@id=\"modal-manager\"]/div/div/div/div/div[3]/span/button";
        await driver.findElement(By.xpath(loginBtnPath))
            .click();

        // Login via Facebook
        let facebookLoginPath = "//*[@id=\"modal-manager\"]/div/div/div/div/div[3]/span/div[2]/button";
        await driver.findElement(By.xpath(facebookLoginPath))
            .click();

        // Waiting for login form
        await sleep(4500);

       // Enter login and password
        let loginPath = "//*[@id=\"email\"]";
        let passPath = "//*[@id=\"pass\"]";
         await driver.findElement(By.xpath(loginPath))
            .sendKeys(MY_MAIL);


You may notice that this script gets an error at the end:
(node:8402) UnhandledPromiseRejectionWarning: NoSuchElementError: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="email"]"}

My assumption is that the facebook login opens in a separate small window (
5edb8d3c6db50219085613.png

How to treat it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question