Selenium Webdriver Study (i)------------Quick Start (reprint Jarvi)

Source: Internet
Author: User

Selenium Webdriver Learning (a)------------Quick start Blog Category:
    • Selenium-webdriver
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
  1. Import Org.openqa.selenium.By;
  2. Import Org.openqa.selenium.WebDriver;
  3. Import org.openqa.selenium.WebElement;
  4. Import Org.openqa.selenium.firefox.FirefoxDriver;
  5. Public class Firstexampe {
  6. public static void Main (string[] args) {
  7. Webdriver Driver = new Firefoxdriver ();
  8. Driver.get ("http://www.google.com.hk");
  9. webelement element = Driver.findelement (By.name ("Q"));
  10. Element.sendkeys ("Hello selenium!");
  11. Element.submit ();
  12. try {
  13. Thread.Sleep (3000);
  14. } catch (Interruptedexception e) {
  15. E.printstacktrace ();
  16. }
  17. System.out.println ("page title is:" + driver.gettitle ());
  18. Driver.quit ();
  19. }
  20. }

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
    1. Page title Is:hello selenium! -Google Search

and close the FF browser.

Selenium Webdriver Study (i)------------Quick Start (reprint Jarvi)

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.