SELENIUM2 (webdirver) Getting Started Environment Building (Java Edition)

Source: Internet
Author: User

Go to the blog: http://www.cnblogs.com/puresoul/p/3483055.html

Operation encountered error: Webdriver Unable to connect to host 127.0.0.1 on port 7055 after 45000 MS Update Selenium-java.jar package to the latest;

* Development environment:

1.jdk1.7

2.eclipse,:http://www.eclipse.org/downloads/

3.selenium-java-2.44.0.jar,:http://docs.seleniumhq.org/download/

Unzip the Selenium-java as shown:

4.firefox 33.1

*eclipse:

1. Create a new Java project: Extract the Selenium-java files to the new project;

2. Add build path, project directory right-click-->build path--> Config build Path-->java build Path-->libraries-->add External JARs

Add all the jar packages under the Libs folder and add selenium-java-2.44.0 and Selenium-java-2.44.0-srcs

3. After adding the directory structure such as, more referenced Libraries, here is the above step added to the jar package

4. Associated Webdriver Source: Expand Referenced Libraries folder, select Selenium-java-2.44.0.jar, right click Properties-->java source attachment-- >external location Select the path where Selenium-java-2.44.0-srcs.jar is located (the path to the current project);

At this point the environment is configured to complete;

Example

1. New test class under SRC: New test Package com.selenium.demo--> new test class Testselenium.java

2. The code is as follows:

Package Com.selenium.Glen;

Import Org.openqa.selenium.By;

Import Org.openqa.selenium.WebDriver;

Import org.openqa.selenium.WebElement;

Import org.openqa.selenium.firefox.*;

public class Testhelloworld {

public static void Main (string[] args) {

If Firefox is not installed by default on the C drive, you need to set its path

System.setproperty ("Webdriver.firefox.bin", "D:/program Files/mozilla firefox/firefox.exe");

Webdriver Driver = new Firefoxdriver ();

Driver.get ("http://www.baidu.com/");

Driver.manage (). window (). Maximize ();

Webelement txtbox = driver.findelement (By.name ("WD"));

Txtbox.sendkeys ("Selenium");

Webelement btn = driver.findelement (by.id ("su"));

Btn.click ();

Driver.close ();

}

}

Then directly right-click-->run As-->java application can see the effect.

SELENIUM2 (webdirver) Getting Started Environment Building (Java Edition)

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.