Java Selenium Start

Source: Internet
Author: User
Tags httpcontext java format

Export the recorded script to the Java format first

Edit and run test in eclipse
2.1 Create a new Java Project:file-new-java project
2.2 Right-click on the project name that you built in the previous step, tap build Path-add External Archives ..., Selenium-java-2.21.0.jar (client) and selenium- will be downloaded server-standalone- 2.21.0.jar (server) Add in

2.3 Start selenium server. Go to cmd and run "Java-jar Selenium-server-standalone-2.21.0.jar"--to ensure that the jar package can be found. The information is as follows:

[Java]View Plaincopy
  1. Information: launching a standalone server
  2. :21.484 Info-java:sun Microsystems Inc. 17.1-b03
  3. :21.500 info-os:windows XP 5.1 x86
  4. :21.515 info-v2. 21.0, with Core v2. 21.0. Built from revision 16552
  5. 21.859:info-remotewebdriver instances should connect To:http://127.0.0.
  6. 1:4444/wd/hub
  7. :21.875 info-version jetty/5.1.x
  8. :21.875 info-started httpcontext[/selenium-server/driver,/selenium-server
  9. /driver]
  10. :21.875 info-started httpcontext[/selenium-server,/selenium-server]
  11. :21.875 info-started httpcontext[/,/]
  12. :22.062 info-started org.openqa.jetty.jetty.servlet.ServletHandler@5d173
  13. :22.062 info-started httpcontext[/wd,/wd]
  14. :22.093 info-started socketlistener on 0.0. 0.0:4444
  15. :22.093 info-started org.openqa.jetty.jetty.Server@32fb4f


2.4 Code Testing

[Java]View Plaincopy
    1. Import Com.thoughtworks.selenium.DefaultSelenium;
    2. Public class SeleniumDemo01
    3. {
    4. public static void Main (string[] args)
    5. {
    6. String host = "localhost";
    7. int port = 4444;
    8. String url = "http://www.baidu.com/";
    9. String BrowserType = "*firefox";
    10. String keywordslocator = "document.getElementById (' kw ')";
    11. String search = "document.getElementById (' su ')";
    12. Defaultselenium Selenium = new Defaultselenium (Host,port,browsertype,url);
    13. Selenium.start ();
    14. Selenium.open (URL);
    15. Selenium.type (Keywordslocator,"Java Selenium");
    16. Selenium.click (search);
    17. Selenium.waitforpagetoload ("50000");
    18. Selenium.stop ();
    19. }
    20. }
    21. Operation Result:
    22. 1.firefox Browser Expectations
    23. 2. Open Baidu homepage
    24. 3. Type "Java Selenium" in the search box
    25. 4. Click on "Baidu button"
    26. 5. Page load 50s
    27. 6. Close the browser
    28. Excerpted from http://blog.csdn.net/test_me/article/details/7471364

Java Selenium Start

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.