Paste #276097

   
pasted on 13.07.2024 18:34
  • Edit to this paste
  • Print
  • Raw
  • Compare with paste
    #  
  • Toggle line numbers
  • Syntax highlighting  
Text paste
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'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};
Add Comment
Author