Selenium Webdriver Learning (a)------------Quick start
Blog Category:
Selenium Webdriver Study
Selenium Webdriver learning process (i)------------Quick Start
Selenium has been studying for two years, from 1. X to 2.X, has been watching it. In the middle due to work interrupted a period of time, but has been unable to give up, recently went to the official website to see a bit, the update is quite fast. Selenium1. The era of x will be replaced, the selenium-webdriver of the Great sailing era began ...
Installing Selenium webdriver (Eclipse+jdk+selenium Webdriver2.20+firefox 10)
1, install Firefox, I use firefox10. Make sure Firefox is installed in the default environment (no error will occur).
2, install the JDK, to ensure that the JDK installed, I like to use Java. But selenium Webdriver also supports other languages such as Ruby, Python, C #, and so on.
3, install Eclipse, personal preferences.
4, install selenium webdriver. Unzip the downloaded Selenium Webdriver package, and you can build a user library in eclipse and bring it to the project.
First Test
Now take a look at the charm of the first selenium webdriver test.
Java code
- Import Org.openqa.selenium.By;
- Import Org.openqa.selenium.WebDriver;
- Import org.openqa.selenium.WebElement;
- Import Org.openqa.selenium.firefox.FirefoxDriver;
- Public class Firstexampe {
- public static void Main (string[] args) {
- Webdriver Driver = new Firefoxdriver ();
- Driver.get ("http://www.google.com.hk");
- webelement element = Driver.findelement (By.name ("Q"));
- Element.sendkeys ("Hello selenium!");
- Element.submit ();
- try {
- Thread.Sleep (3000);
- } catch (Interruptedexception e) {
- E.printstacktrace ();
- }
- System.out.println ("page title is:" + driver.gettitle ());
- Driver.quit ();
- }
- }
After normal operation, these lines of code will open the Firefox browser and then go to the Google home page. Enter the hello selenium in the search box and submit the search results. After 3 seconds, the title of the current page is printed on the command line, and the output is as follows:
Java code
- Page title Is:hello selenium! -Google Search
and close the FF browser.
Selenium Webdriver Study (i)------------Quick Start (reprint Jarvi)