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
- fixed getRandomNum
- Issue was – at that twitter acc 2fa was disabled. script should handle that
New contributor
kaka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.