Created
September 5, 2021 04:53
-
-
Save riteshkawadkar/8ded186fcd7a33cdd736cf4cf9bd0a6a to your computer and use it in GitHub Desktop.
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
using OpenQA.Selenium; | |
using OpenQA.Selenium.Chrome; | |
using OpenQA.Selenium.Interactions; | |
using OpenQA.Selenium.Support.UI; | |
using System; | |
namespace BigoBot.Bot | |
{ | |
class AutoBot | |
{ | |
public static void initiate(string _url, string _country, string _mobile, string _pass, string _comment, int rowNo) | |
{ | |
//var AppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); | |
//var profilePath = AppData + "\\Local\\Google\\Chrome\\User Data"; | |
//ChromeOptions options = new ChromeOptions(); | |
//options.AddArguments("user-data-dir=" + profilePath); | |
//options.AddArguments("disable-infobars"); | |
//options.AddAdditionalCapability("useAutomationExtension", false); | |
//options.AddExcludedArgument("enable-automation"); | |
//options.AddArgument("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"); | |
//options.AddArguments("headless"); | |
//IWebDriver driver = new ChromeDriver(options); | |
IWebDriver driver = new ChromeDriver(); | |
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(120)); | |
IJavaScriptExecutor js = (IJavaScriptExecutor)driver; | |
try | |
{ | |
driver.Manage().Window.Maximize(); | |
driver.Navigate().GoToUrl("https://www.bigo.tv/"); | |
driver.Navigate().GoToUrl(_url); | |
System.Threading.Thread.Sleep(3000); | |
driver.Navigate().Refresh(); | |
driver.Navigate().Refresh(); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Driver Not found"); | |
return; | |
} | |
// Get All available cookies | |
//var cookies = driver.Manage().Cookies.AllCookies; | |
//foreach (Cookie tempCookie in cookies) | |
//{ | |
// Console.WriteLine(tempCookie.Name + " " + tempCookie.Value); | |
//} | |
System.Threading.Thread.Sleep(3000); | |
try | |
{ | |
var languageButton = wait.Until(x => x.FindElement(By.XPath("//li[@class='btn-lang'][1]"))); | |
languageButton.Click(); | |
} | |
catch (Exception e) | |
{ | |
closeBotGracefully(e, driver, rowNo, "Language Button Not found"); | |
return; | |
} | |
System.Threading.Thread.Sleep(1000); | |
try | |
{ | |
var languageList = wait.Until(x => x.FindElement(By.XPath("//div[@class='lang-list']//a[text()='English']"))); | |
languageList.Click(); | |
} | |
catch (Exception e) | |
{ | |
closeBotGracefully(e, driver, rowNo, "Language List Not found"); | |
return; | |
} | |
System.Threading.Thread.Sleep(1000); | |
try | |
{ | |
var loginButton = wait.Until(x => x.FindElement(By.XPath("//button[@class='head-right__login__btn']"))); | |
loginButton.Click(); | |
} | |
catch (Exception e) | |
{ | |
closeBotGracefully(e, driver, rowNo, "Login Button Not found"); | |
return; | |
} | |
System.Threading.Thread.Sleep(1000); | |
try | |
{ | |
var mobileButton = wait.Until(x => x.FindElement(By.XPath("//button[@class='other-login__box__phone']"))); | |
mobileButton.Click(); | |
} | |
catch (Exception e) | |
{ | |
closeBotGracefully(e, driver, rowNo, "Mobile Button Not found"); | |
return; | |
} | |
try | |
{ | |
//if country is already selected then don't run country selection code | |
var selected_country = wait.Until(x => x.FindElement(By.XPath("//p[@class='current_selected']"))); | |
if (selected_country.Text.Contains(_country)) | |
{ | |
// do nothing | |
} | |
else | |
{ | |
// select the drop down list | |
var country = wait.Until(x => x.FindElement(By.ClassName("CountrySelect-Component"))); | |
System.Threading.Thread.Sleep(1000); | |
country.Click(); | |
// Get country list | |
var countryList = wait.Until(x => x.FindElement(By.ClassName("country_list"))); | |
System.Threading.Thread.Sleep(1000); | |
var countryNameList = wait.Until(x => x.FindElements(By.XPath("//li/span[@class='country_name']/parent::li"))); | |
//countryNameList[171].Click(); | |
foreach (IWebElement countryName1 in countryNameList) | |
{ | |
js.ExecuteScript("arguments[0].scrollIntoView(true);", countryName1); | |
System.Threading.Thread.Sleep(10); | |
//Console.WriteLine(countryName1.Text); | |
if (countryName1.Text.Contains(_country)) | |
{ | |
// select Russia | |
countryName1.Click(); | |
} | |
} | |
} | |
} | |
catch(Exception e) | |
{ | |
closeBotGracefully(e, driver, rowNo, "Selected Country DropDown Not found"); | |
return; | |
} | |
System.Threading.Thread.Sleep(500); | |
try | |
{ | |
var mobilePhoneTextBox = wait.Until(x => x.FindElement(By.XPath("//div[@class='phone-number-box']//input"))); | |
mobilePhoneTextBox.Clear(); | |
mobilePhoneTextBox.SendKeys(_mobile); | |
} | |
catch (Exception e) | |
{ | |
closeBotGracefully(e, driver, rowNo, "Mobile No Text Not found"); | |
return; | |
} | |
System.Threading.Thread.Sleep(500); | |
try | |
{ | |
var passwordTextBox = wait.Until(x => x.FindElement(By.XPath("//div[@class='password-tab']//input"))); | |
passwordTextBox.Clear(); | |
passwordTextBox.SendKeys(_pass); | |
} | |
catch (Exception e) | |
{ | |
closeBotGracefully(e, driver, rowNo, "Pass Text Not found"); | |
return; | |
} | |
System.Threading.Thread.Sleep(1000); | |
try | |
{ | |
var sliderbegin = wait.Until(x => x.FindElement(By.Id("captcha-box-login-bigo-captcha-element-bigo-captcha-sliderele"))); | |
Actions dragger = new Actions(driver); | |
dragger.ClickAndHold(sliderbegin).Build().Perform(); | |
for (int i = 0; i < 25; i++) | |
{ | |
dragger.MoveByOffset(i, 0); | |
} | |
try | |
{ | |
dragger.Release().Build().Perform(); | |
} | |
catch | |
{ | |
Console.WriteLine("Outside target"); | |
} | |
} | |
catch (Exception e) | |
{ | |
// do nothing verification failed | |
closeBotGracefully(e, driver, rowNo, "Slider Not found"); | |
return; | |
} | |
System.Threading.Thread.Sleep(3000); | |
try | |
{ | |
var status = wait.Until(x => x.FindElement(By.Id("captcha-box-login-bigo-captcha-element-bigo-captcha-textelediv"))); | |
if (status.Text.Contains("verification failed")) | |
{ | |
driver.Close(); | |
driver.Quit(); | |
return; | |
} | |
} | |
catch (Exception e) | |
{ | |
closeBotGracefully(e, driver, rowNo, "Verification Status Not found"); | |
return; | |
} | |
System.Threading.Thread.Sleep(1000); | |
try | |
{ | |
var submitButton = wait.Until(x => x.FindElement(By.XPath("//button[@class='btn-sumbit']"))); | |
submitButton.Click(); | |
} | |
catch (Exception e) | |
{ | |
closeBotGracefully(e, driver, rowNo, "Submit Button Not found"); | |
return; | |
} | |
System.Threading.Thread.Sleep(3000); | |
try | |
{ | |
var commentTextBox = wait.Until(x => x.FindElement(By.XPath("//div[@class='user_sent_msg']//textarea"))); | |
commentTextBox.SendKeys(_comment); | |
} | |
catch (Exception e) | |
{ | |
closeBotGracefully(e, driver, rowNo, "Comment Text Not found"); | |
return; | |
} | |
System.Threading.Thread.Sleep(1000); | |
try | |
{ | |
var sendButton = wait.Until(x => x.FindElement(By.XPath("//div[@class='user_sent_msg']//a[@class='send_btn']"))); | |
sendButton.Click(); | |
} | |
catch (Exception e) | |
{ | |
closeBotGracefully(e, driver, rowNo, "Send Button Not found"); | |
return; | |
} | |
System.Threading.Thread.Sleep(500); | |
driver.Close(); | |
driver.Quit(); | |
} | |
public static void closeBotGracefully(Exception e, IWebDriver driver, int rowNo, string msg) | |
{ | |
Console.WriteLine(msg); | |
Console.WriteLine(e.Message); | |
if (Globals.stop_engine) | |
{ | |
Console.WriteLine("Stopping Engine"); | |
return; | |
} | |
Globals.bot_status = false; | |
driver.Close(); | |
driver.Quit(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment