'use strict'; const {Browser,Builder, By, Key} = require('selenium-webdriver'); const config = require('./config'); const {getTotpToken, getRandomNum} = require ('./jsTools') 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); await driver.sleep(getRandomNum()); const username = await driver.findElement(By.xpath("//input[@autocomplete='username']")); await driver.sleep(getRandomNum()); await username.sendKeys(config.twitter.login); await driver.sleep(getRandomNum()); await username.sendKeys(Key.RETURN); await driver.sleep(getRandomNum()); const phoneNumber = await driver.findElement(By.xpath("//input")); await driver.sleep(getRandomNum()); await phoneNumber.sendKeys(config.twitter.phone); await driver.sleep(getRandomNum()); await phoneNumber.sendKeys(Key.RETURN); await driver.sleep(getRandomNum()); const password = await driver.findElement(By.xpath("//input[@autocomplete='current-password']")); await driver.sleep(getRandomNum()); await password.sendKeys(config.twitter.pass); await driver.sleep(getRandomNum()); await password.sendKeys(Key.RETURN); await driver.sleep(getRandomNum()); const totpToken = await driver.findElement(By.xpath("//input")); // await driver.sleep(getRandomNum()); await totpToken.sendKeys(getTotpToken()); // await driver.sleep(getRandomNum()); await totpToken.sendKeys(Key.RETURN); await driver.sleep(60000); } catch (error){ if(error){ console.error(error.message); } }finally { await driver.quit(); } } module.exports = {twitterLogin};