Advertisement
TermSpar

Selenium WebDriver Auto-Fill

Feb 21st, 2019
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using OpenQA.Selenium;
  11. using OpenQA.Selenium.Chrome;
  12. using OpenQA.Selenium.Interactions;
  13.  
  14. namespace AutoFill
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void button1_Click(object sender, EventArgs e)
  24.         {
  25.             ChromeDriver driver = new ChromeDriver();
  26.             driver.Navigate().GoToUrl("https://www.famousfootwear.com/account/login#!/account-lookup");
  27.  
  28.             IWebElement emailBox = driver.FindElementByCssSelector("#account-email");
  29.             IWebElement signUp = driver.FindElementByCssSelector("#lookupForm > button");
  30.  
  31.             if(emailBox != null)
  32.             {
  33.                 //Auto-fill email:
  34.                 Actions actions = new Actions(driver);
  35.                 actions.MoveToElement(emailBox);
  36.                 actions.Click();
  37.                 actions.SendKeys("example@yahoo.com");
  38.  
  39.                 //Click sign-up button:
  40.                 actions.MoveToElement(signUp);
  41.                 actions.Click();
  42.  
  43.                 //Perform actions:
  44.                 actions.Build().Perform();
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement