Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- using OpenQA.Selenium;
- using OpenQA.Selenium.Support.UI;
- using OpenQA.Selenium.Chrome;
- using System.Threading;
- using System.Text.RegularExpressions;
- using Keys = System.Windows.Forms.Keys;
- namespace Gmail_Scrape
- {
- public partial class frm_Gmail : Form
- {
- public frm_Gmail()
- {
- InitializeComponent();
- }
- private void frm_Gmail_KeyUp(object sender, KeyEventArgs e)
- {
- //// Enable & Disable Button
- //if (txtBox_User.TextLength > 5 && txtBox_Pass.TextLength > 2)
- //{
- // btn_Login.Enabled = true;
- // btn_Delete.Enabled = true;
- //}
- //else
- //{
- // btn_Login.Enabled = false;
- // btn_Delete.Enabled = false;
- //}
- }
- private void btn_Login_Click(object sender, EventArgs e)
- {
- this.Enabled = false;
- this.Cursor = Cursors.WaitCursor;
- try
- {
- // Declare Url of Gmail
- string UrlGmail = "https://mail.google.com/mail/";
- // email & node email
- string email = txtBox_User.Text;
- string Node_email = "//*[@type='email']";
- // password & node password
- string pass = txtBox_Pass.Text;
- string Node_pass = "//*[@type='password']";
- // Nodes of Button Next
- string email_Next = "//*[@id='identifierNext']";
- string pass_Next = "//*[@id='passwordNext']";
- // Create the reference for our browser
- IWebDriver driver = new ChromeDriver(); // path of chrome driver is Optional
- WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
- // Navigate to Gmail.com
- driver.Navigate().GoToUrl(UrlGmail);
- // Maximize Navigator
- driver.Manage().Window.Maximize();
- // Implicitly Wait
- //driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
- //driver.Manage().Timeouts().ImplicitWait(TimeSpan.FromSeconds(20));
- // Enter Email and click next button
- driver.FindElement(By.XPath(Node_email)).SendKeys(email);
- driver.FindElement(By.XPath(email_Next)).Click();
- Thread.Sleep(5000); // Wait 4 milisecond
- //driver.Manage().Timeouts().PageLoadTimeout(TimeSpan.FromSeconds(40));
- //wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(Node_pass)));
- // Enter Password and click next button
- driver.FindElement(By.XPath(Node_pass)).SendKeys(pass);
- driver.FindElement(By.XPath(pass_Next)).Click();
- Thread.Sleep(5000); // Wait 4 milisecond
- // Click to Social Media Messages
- string value_SM = "Messages provenant de réseaux sociaux, de sites de partage de fichiers multimédia, de sites de rencontre en ligne et autres sites Web sociaux.";
- driver.FindElement(By.XPath("//*[@data-tooltip='" + value_SM + "']")).Click();
- // Node of button delete
- string node_Delet = "//div[@class='nH aqK']/div/div/div/div[2]/div[3]";
- // Node of Selectionner Tout
- string SelectAll = "//*[@aria-label='Sélectionner']/div[1]/span";
- // see if messages SM exit or not
- IWebElement slide = driver.FindElement(By.XPath("//*[@class='ar5 J-J5-Ji']"));
- string vide = slide.Text;
- if (vide != " ")
- {
- // Declare number of Messages in page
- string node_NbrOfmessage = "//div[@aria-label='Afficher plus de messages']/span/span[1]/span[2]";
- IWebElement nbrValue = driver.FindElement(By.XPath(node_NbrOfmessage));
- // Declare number of pages Messages
- string node_NbrOfPages = "//div[@aria-label='Afficher plus de messages']/span/span[2]";
- IWebElement nbrOfPage = driver.FindElement(By.XPath(node_NbrOfPages));
- // Start Conversion
- // convert number of messages in page to integer
- string nbr_Messages = nbrValue.Text;
- int j = Convert.ToInt32(nbr_Messages);
- // convert number of pages messages to integer
- string nbr_Pages = nbrOfPage.Text;
- // Replace space
- nbr_Pages = Regex.Replace(nbr_Pages, @"\s", "");
- int h = Convert.ToInt32(nbr_Pages);
- // End Conversion.
- // Show informations in Riche Text Box ..
- rtxtBox.Text = "your Totale social media messages is : " + h + "\n\n";
- while (j != h)
- {
- // Select All Messages in page
- driver.FindElement(By.XPath(SelectAll)).Click();
- // Delet Messages Selected
- driver.FindElement(By.XPath(node_Delet)).Click();
- Thread.Sleep(12000);
- // Restart Value
- nbrValue = driver.FindElement(By.XPath(node_NbrOfmessage));
- nbrOfPage = driver.FindElement(By.XPath(node_NbrOfPages));
- nbr_Messages = nbrValue.Text;
- j = Convert.ToInt32(nbr_Messages);
- nbr_Pages = nbrOfPage.Text;
- nbr_Pages = Regex.Replace(nbr_Pages, @"\s", "");
- h = Convert.ToInt32(nbr_Pages);
- }
- if (j == h)
- {
- // Select All Messages in page
- driver.FindElement(By.XPath(SelectAll)).Click();
- // Delet Messages Selected
- driver.FindElement(By.XPath(node_Delet)).Click();
- }
- }
- else
- rtxtBox.Text = "Your \"Social Networks\" tab is empty";
- // Click to Promotions Messages
- string value_Promotion = "//*[@data-tooltip='Promotions, offres et autres messages commerciaux.']";
- driver.FindElement(By.XPath(value_Promotion)).Click();
- // see if messages PROMO exit or not
- slide = driver.FindElement(By.XPath("//*[@class='ar5 J-J5-Ji']"));
- vide = slide.Text;
- if (vide != " ")
- {
- // Declare number of Messages in page
- string node_NbrOfmessageP = "//div[@aria-label='Afficher plus de messages']/span/span[1]/span[2]";
- IWebElement nbrValueP = driver.FindElement(By.XPath(node_NbrOfmessageP));
- // Declare number of pages Messages
- string node_NbrOfPagesP = "//div[@aria-label='Afficher plus de messages']/span/span[2]";
- IWebElement nbrOfPageP = driver.FindElement(By.XPath(node_NbrOfPagesP));
- // Start Conversion
- // convert number of messages in page to integer
- string nbr_MessagesP = nbrValueP.Text;
- int jj = Convert.ToInt32(nbr_MessagesP);
- // convert number of pages messages to integer
- string nbr_PagesP = nbrOfPageP.Text;
- nbr_PagesP = Regex.Replace(nbr_PagesP, @"\s", "");
- int hh = Convert.ToInt32(nbr_PagesP);
- // End Conversion.
- // Show informations in Riche Text Box ..
- rtxtBox2.Text = "And your Totale Promotions messages is : " + hh + "\n\n";
- while (jj != hh)
- {
- // Select All Messages in page
- driver.FindElement(By.XPath(SelectAll)).Click();
- // Delet Messages Selected
- driver.FindElement(By.XPath(node_Delet)).Click();
- Thread.Sleep(12000);
- // Restart Value
- nbrValueP = driver.FindElement(By.XPath(node_NbrOfmessageP));
- nbrOfPageP = driver.FindElement(By.XPath(node_NbrOfPagesP));
- nbr_MessagesP = nbrValueP.Text;
- jj = Convert.ToInt32(nbr_MessagesP);
- nbr_PagesP = nbrOfPageP.Text;
- nbr_PagesP = Regex.Replace(nbr_PagesP, @"\s", "");
- hh = Convert.ToInt32(nbr_PagesP);
- }
- if (jj == hh)
- {
- // Select All Messages in page
- driver.FindElement(By.XPath(SelectAll)).Click();
- // Delet Messages Selected
- driver.FindElement(By.XPath(node_Delet)).Click();
- Thread.Sleep(1000);
- }
- }
- else
- rtxtBox2.Text = "Your \"Promotions\" tab is empty";
- // Close Browser & Driver
- driver.Close();
- driver.Quit();
- // Show Message << your social media messages was deleted >> ..
- MessageBox.Show("Social Media & Promotions Messages was successful deleted"
- + "\n\n" + "Gongralutation ..",
- "Messages Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- this.Enabled = true;
- this.Cursor = Cursors.Default;
- }
- private void btn_Exit_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void txtBox_Pass_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == (char)Keys.Enter)
- {
- btn_Login.PerformClick();
- }
- }
- private void btnAbout_Click(object sender, EventArgs e)
- {
- AboutBox frmAbout = new AboutBox();
- frmAbout.ShowDialog();
- }
- private void btnShow2_Click(object sender, EventArgs e)
- {
- txtBox_Pass.PasswordChar = '\0';
- btnShow2.Visible = false;
- labelShow.Visible = false;
- }
- private void btnShow_Click(object sender, EventArgs e)
- {
- txtBox_Pass.PasswordChar = char.Parse("◉");
- btnShow2.Visible = true;
- labelShow.Visible = true;
- }
- private void txtBox_Pass_KeyUp(object sender, KeyEventArgs e)
- {
- // Enable & Diable Button Show
- //if (txtBox_Pass.TextLength > 1)
- // btn_Login.Enabled = true;
- //else
- // btn_Login.Enabled = false;
- }
- private void AboutHover1_MouseHover(object sender, EventArgs e)
- {
- AboutHover1.Visible = false;
- }
- private void btnAbout_MouseLeave(object sender, EventArgs e)
- {
- AboutHover1.Visible = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement