-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkingsfollowauto.js
164 lines (141 loc) · 6.42 KB
/
kingsfollowauto.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
'use strict';
const webDriver = require('selenium-webdriver');
const {Builder, Key, until} = require('selenium-webdriver');
//to load chrome driver
require('chromedriver');
var chromeCapabilities= webDriver.Capabilities.chrome()
var chromeOptions={'args':['--test-type','--incognito']}
chromeCapabilities.set('chromeOptions',chromeOptions)
const excelToJson = require('convert-excel-to-json');
var fs = require('fs');
var startdata=fs.readFileSync('startkingschat.txt').toString()
startdata= JSON.parse(startdata.trim())
console.log(startdata)
var datastart = parseInt(startdata.datastart)
var dataend= parseInt(startdata.dataend)
if(isNaN(dataend)) dataend = result.Sheet1.length
const result = excelToJson({
sourceFile: 'DATAMARCH.xlsx',
header:{
rows: 1
},
columnToKey: {
C: 'USERNAME',
D: 'PASSWORD'
}
});
//console.log(result)
let By = webDriver.By;
let driver= new webDriver.Builder().withCapabilities(chromeCapabilities).build();
//let driver = new webDriver.Builder().forBrowser('chrome').build();
(async function () {
var count=0
for (var i=datastart;i<=dataend;i++) {
try {
await driver.get('https://www.kingsch.at/h/');
await driver.findElement(By.css('.kc-web-link')).click();
await driver.wait(until.titleIs('Accounts | Login'),25000);
let inp2 = await driver.wait(until.elementLocated(By.xpath("//*[@type='text' and @name='login' and @placeholder='Username, Phone Number or E-mail']")), 10000);
await inp2.sendKeys(result.Sheet1[i].USERNAME,Key.TAB)
await driver.sleep(3000)
let inp= await driver.wait(until.elementLocated(By.xpath("//*[@type='password' and @name='password' and @placeholder='Password']")), 10000);
await inp.sendKeys(result.Sheet1[i].PASSWORD,Key.ENTER)
// await driver.wait(until.titleIs('Accounts | Login'), 3000);
try{
await driver.wait(until.elementLocated(By.css('.NoficationPopup__button')),15000).click();
}catch(error){
console.log('notification button not found')
}
let inp3 = await driver.wait(until.elementLocated(By.css('.Navbar__search__input')),15000);
await driver.sleep(4000)
//await driver.Key('ESCAPE');
await inp3.sendKeys('CE port harcourt zone 3', Key.ENTER);
await driver.sleep(3000)
await driver.get('https://web.kingsch.at/search/CE%20port%20harcourt%20zone%203/superusers')
try{
await driver.wait(until.elementLocated(By.css('.SuperuserCard__unfollow')),5000);
}catch(error) {
let inp4= await driver.wait(until.elementLocated(By.css('.SuperuserCard__follow')),40000);
await driver.sleep(3000)
await inp4.click()
await driver.sleep(1000)
await inp4.click()
await driver.sleep(1000)
await inp4.click()
await driver.sleep(2000)
}
try{
await driver.wait(until.elementLocated(By.css('.SuperuserCard__unfollow')),20000);
}catch(error) {
let inp4= await driver.wait(until.elementLocated(By.css('.SuperuserCard__follow')),40000);
await driver.sleep(3000)
await inp4.click()
await driver.sleep(1000)
await inp4.click()
await driver.sleep(1000)
await inp4.click()
await driver.sleep(2000)
}
/* let inp4= await driver.wait(until.elementLocated(By.css('.SuperuserCard__follow')),40000);
await inp4.click()
driver.sleep(2000)
await inp4.click()
driver.sleep(2000)
await inp4.click()
driver.sleep(2000)
await inp4.click()
driver.sleep(2000)
driver.sleep(4000) */
await driver.findElement(By.css('.Navbar__item-description')).click()
await driver.wait(until.elementLocated(By.css('.Post__author-name')),6000);
await driver.wait(until.elementLocated(By.css('.nav-profile__avatar')), 6000);
await driver.findElement(By.css('.nav-profile__avatar')).click()
await driver.wait(until.elementLocated(By.css('.icon-logout')), 6000);
await driver.findElement(By.css('.icon-logout')).click()
console.log('done /// '+i)
console.log('==================================')
}
catch (error) {
try{
let errele= await driver.wait(until.elementLocated(By.css('.Login__error-message')), 6000)
let errtext= await errele.getText()
if(errtext.indexOf('Wrong Username')!=-1|| errtext.indexOf('confirmed')!=-1){
continue
console.log(i+' wrong username or user not confirmed')
}else{
++count
console.log(error)
console.log('IN/// '+i+'RETRYING')
console.log('==================================')
if (count>=2){
++i
count=0
}else{
--i
}
try{
await driver.wait(until.elementLocated(By.css('.nav-profile__avatar')), 6000);
await driver.findElement(By.css('.nav-profile__avatar')).click()
await driver.wait(until.elementLocated(By.css('.icon-logout')), 6000);
await driver.findElement(By.css('.icon-logout')).click()
}
catch (error){
console.log(error)
}
}
} catch(er){
console.log(error+'IN '+ result.Sheet1[i].USERNAME)
try{
await driver.wait(until.elementLocated(By.css('.nav-profile__avatar')), 6000);
await driver.findElement(By.css('.nav-profile__avatar')).click()
await driver.wait(until.elementLocated(By.css('.icon-logout')), 6000);
await driver.findElement(By.css('.icon-logout')).click()
}
catch (error){
console.log(error)
}
}
}
}
//}
})()