0

I have suck script for Twitter login automation. I've set waits on 21 line and I script to wait on 34 line. But driver.sleep on line 34 doesn't work

'use strict';
const {Browser,Builder, By, Key} = require('selenium-webdriver');
const config = require('./config');
const {TOTP} = require('totp-generator');

function getRandomNum() {
    const min = 5000;
    const max = 10000;
    return Math.random() * (max - min) + min;
}

function getToptpToken() {
    const { otp, expires } = TOTP.generate(config.twitter.toptp.token);
    return otp;
}

async function twitterLogin() {
    const url = 'https://x.com/i/flow/login';
    const driver = await new Builder().forBrowser(Browser.CHROME).build();
    try{
        await driver.manage().setTimeouts({ implicit: 20000 });
        await driver.get(url)
        const username = await driver.findElement(By.xpath("//input[@autocomplete='username']"));
        await username.sendKeys(config.twitter.login);
        await username.sendKeys(Key.RETURN);
        const phoneNumber = await driver.findElement(By.xpath("//input"));
        await phoneNumber.sendKeys(config.twitter.phone);
        await phoneNumber.sendKeys(Key.RETURN);
        const password = await driver.findElement(By.xpath("//input[@autocomplete='current-password']"));
        await password.sendKeys(config.twitter.pass);
        await password.sendKeys(Key.RETURN);
        const totpToken = await driver.findElement(By.xpath("//input"));
        await totpToken.sendKeys(Key.RETURN);
        await driver.sleep(getRandomNum());
    } catch (error){
        if(error === 'NoSuchElementError'){
            console.error(error.message);
        }
    }finally {
        await driver.quit();
    }
}

twitterLogin()

I've googled, tryed different combination of waits....


UPD. Can be closed

  1. fixed getRandomNum
  2. Issue was - at that twitter acc 2fa was disabled. script should handle that
1
  • Post the solution as the answer and mark it as your answer. That way you will have a Q&A format with accepted answer. In the future, when you suspect that one specific thing like sleep is not working, try deleting other things to simplify your test. That way you'll know for sure, and you won't have the other complex functionality in your way. Commented Jul 13, 2024 at 11:32

1 Answer 1

0

Issue was - at that twitter acc 2fa was disabled. script should handle that

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.