Last active
April 20, 2019 09:06
-
-
Save SwapnilSoni1999/7f9341ebf8e5b7c7492a8ce70fa6f376 to your computer and use it in GitHub Desktop.
Realme Contest R-Power Script - Selenium Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const webdriver = require('selenium-webdriver'), | |
By = webdriver.By, | |
Keys = webdriver.Key; | |
until = webdriver.until; | |
const chrome = require('selenium-webdriver/chrome'); | |
const proxy = require('selenium-webdriver/proxy'); | |
const path = require('chromedriver').path; | |
//env | |
var currentpath = process.cwd(); | |
if(process.platform == 'win32') { | |
process.env.PATH += currentpath + "\\chromedriver\\chromedriver.exe;"; | |
} else if(process.platform == 'linux') { | |
process.env.PATH += currentpath + "/chromedriver/chromedriver"; | |
} | |
let options = new chrome.Options(), | |
optionCap = options.addArguments(["--disable-notifications", "--incognito"]); | |
let driver = new webdriver.Builder().forBrowser('chrome').withCapabilities(optionCap.toCapabilities()).build(); | |
let accion = new webdriver.ActionSequence(driver); | |
function main() { | |
driver.get("http://google.com/search?q=myip"); | |
driver.findElement(By.xpath('//*[@id="rso"]/div[1]/div/div/div[1]/div[1]/w-answer/w-answer-desktop/div[1]')).getAttribute('innerHTML').then(function(ip){ | |
console.log("Current IP:",ip); | |
}); | |
// driver.get("https://www.google.com/search?q=myip"); | |
// driver.sleep(5000); | |
driver.get("https://www.mohmal.com/en"); | |
//driver.executeScript('window.open("https://event.realme.com/in/realme-yo-day/r-power.html?userId=425846886");'); | |
driver.executeScript('window.open("https://id.realme.com/register.html");'); | |
driver.getAllWindowHandles().then(function(handles) { | |
console.log(handles); | |
driver.switchTo().window(handles[0]); | |
// driver.findElement(By.id('mail')).getAttribute('value').then(mail => { | |
driver.findElement(By.id('rand')).click(); | |
driver.findElement(By.xpath('//*[@id="email"]/div[1]')).getAttribute('data-email').then(mail => { | |
console.log("Temp-mail id: ",mail); | |
driver.switchTo().window(handles[1]); | |
driver.wait(until.elementLocated(By.xpath('//*[@id="zoneInput"]/div[1]/input')), 35000, 'Cant find input'); | |
driver.findElement(By.xpath('//*[@id="zoneInput"]/div[1]/i')).click(); | |
driver.sleep(1000); | |
let zun = driver.findElement(By.xpath('//*[@id="zoneInput"]/div[1]/input')).click(); | |
accion.sendKeys(Keys.TAB); | |
accion.sendKeys(mail); | |
driver.sleep(1000); | |
accion.sendKeys(Keys.TAB).perform(); | |
//send verification | |
driver.findElement(By.css('#app > div > div.box > div.box_content > div > div.input.codes.codeWrap > div.input_code')).click(); | |
//switch tab and get code | |
driver.sleep(10 * 1000); | |
driver.switchTo().window(handles[0]); | |
driver.sleep(12*1000).then(function() { | |
//*[@id="mails"]/tbody/tr/td[3]/a | |
driver.findElement(By.id('refresh')).click(); | |
console.log("Retriving Verification code"); | |
driver.wait(until.elementLocated(By.xpath('//*[@id="inbox-table"]/tbody/tr/td[1]/a')),20000, 'no mail'); | |
driver.findElement(By.xpath('//*[@id="inbox-table"]/tbody/tr/td[1]/a')).click(); | |
driver.sleep(7000).then(function() { | |
driver.switchTo().frame(driver.findElement(By.css('#read > div.body > iframe'))); | |
driver.executeScript(` | |
var kek = document.querySelector('body > div > div > div:nth-child(2) > b').innerHTML; | |
return kek; | |
`).then(function (code) { | |
console.log("Verification code is : ", code); | |
//change to login page | |
driver.switchTo().defaultContent(); | |
driver.switchTo().window(handles[1]); | |
driver.sleep(1000); | |
driver.findElement(By.css('#app > div > div.box > div.box_content > div > div.input.codes.codeWrap > input[type="text"]')).sendKeys(code); | |
driver.findElement(By.xpath('//*[@id="app"]/div/div[2]/div[2]/div/div[4]/i')).click(); | |
driver.findElement(By.xpath('//*[@id="app"]/div/div[2]/div[2]/div/button')).click(); | |
driver.sleep(3000); | |
driver.wait(until.elementLocated(By.css('#app > div > div.box.boxMid > div.box_content > div > div:nth-child(1) > input[type="password"]')), 10000, 'kek1'); | |
driver.findElement(By.css('#app > div > div.box.boxMid > div.box_content > div > div:nth-child(1) > input[type="password"]')).sendKeys("9824swapneelk3k"); | |
driver.findElement(By.xpath('//*[@id="app"]/div/div[2]/div[2]/div/div[2]/input')).sendKeys("9824swapneelk3k"); | |
driver.sleep(1000); | |
driver.findElement(By.xpath('//*[@id="app"]/div/div[2]/div[2]/div/button')).click(); | |
//wait for redirect | |
driver.sleep(1000); | |
//finally send r-power | |
driver.get("https://event.realme.com/in/realme-yo-day/r-power.html?userId=425846886"); | |
driver.wait(until.elementLocated(By.xpath('//*[@id="app"]/div[3]/div/div[4]/button[1]')), 6000, 'press F nibba'); | |
driver.findElement(By.xpath('//*[@id="app"]/div[3]/div/div[4]/button[1]')).click().then(function() { | |
console.log("R-Power successfully sent! to Swapnil"); | |
}); | |
}); | |
driver.sleep(1500); | |
driver.get("https://event.realme.com/in/realme-yo-day/r-power.html?userId=425777434"); | |
driver.wait(until.elementLocated(By.xpath('//*[@id="app"]/div[3]/div/div[4]/button[1]')), 6000, 'press F nibba'); | |
driver.findElement(By.xpath('//*[@id="app"]/div[3]/div/div[4]/button[1]')).click().then(function() { | |
console.log("R-Power successfully sent! to Ritik"); | |
}); | |
}); | |
}); | |
}); | |
}); | |
driver.sleep(3000); | |
driver.quit(); | |
} | |
main(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment