Selenium super simple Get Started "turn"

Source: Internet
Author: User

Import Org.openqa.selenium.By;
Import Org.openqa.selenium.WebDriver;
Import org.openqa.selenium.WebElement;
Import Org.openqa.selenium.chrome.ChromeDriver;

/**
* This program demonstrates: with selenium, the process of launching the Chrome browser and logging into the QQ mailbox
*
* @author Lizeyang
*
*/
public class Seleniumutil
{
The path of the browser program
Private String Webbrowserpath = "";

Private Webdriver driver = null;

Private String loginurl = "https://mail.qq.com/cgi-bin/loginpage";//Login page of QQ mailbox
Private String username = "10000"; QQ Account
Private String Password = "HelloWorld"; QQ Password

Initializes the selenium to invoke and launches the browser
public void Init ()
{
Webbrowserpath = "D:/webdriver/chromedriver.exe";
System. SetProperty ("Webdriver.chrome.driver", Webbrowserpath);
Driver = new Chromedriver ();
}

Close browser
public void Quitdrvier ()
{
if (null! = driver)
{
Driver. Quit ();
}
}

public void Waitforsecond ()
{
Try
{
Thread. Sleep (1000);
}
catch (Interruptedexception e)
{
E.printstacktrace ();
}
}

Simulating the logon process
public void Login ()
{
Driver. Get (loginurl); Enter the QQ login page
webelement element = driver. Findelement (by.id ("UIn"));//find DOM element with ID named UIn
Element.sendkeys (username);//The current element is the UIn input box, fill in the user name into this input box
Waitforsecond (); Let the process wait for a while to avoid occasional elements getting an exception
element = driver. Findelement (By.id ("P"));//find DOM element with ID named P
Element.sendkeys (password);//fill in the password
Waitforsecond ();
element = driver. Findelement (by.id ("Btlogin"));//Find Login button
Waitforsecond ();
Element.click (); Click the login button
}

public void Demo ()
{
Init ();
Login ();
Quitdrvier ();
}

public static void Main (string[] args)
{
Seleniumutil util = new Seleniumutil ();
Util.demo ();
}

}

Selenium super simple Get Started "turn"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.