Selenium --- encapsulation example

Source: Internet
Author: User

1. Create two inheritance classes under the same package:

2. The code implementation in the class is:

Package org. codeinfo. Demo;

Import java. util. Concurrent. timeunit;

Import org. openqa. Selenium.;
Import org. openqa. Selenium. WebDriver;
Import org. openqa. Selenium. Firefox. firefoxdriver;

Public class utils {
WebDriver driver = new firefoxdriver ();

Public void sendkeys (by, string value ){
Driver. findelement (by). sendkeys (value );
}

Public void click (){
Driver. findelement (by). Click ();
Driver. Manage (). timeouts (). implicitlywait (5000, timeunit. Seconds );
}

}

------------------------------------------------------------------------

Package org. codeinfo. Demo;

Import org. openqa. Selenium.;
Import org. openqa. Selenium. WebDriver;
Import org. openqa. Selenium. Firefox. firefoxdriver;

Public class utilsextends extends utils {
Public static void main (string ARGs []) {
Utils util = new utils ();

Util. Driver. navigate (). To ("http://www.baidu.com"); // open Baidu Homepage

Util. sendkeys (by. XPath (". // * [@ ID = 'kw ']"), "Selenium"); // enter selenium in the text box

Util. Click (by. XPath (". // * [@ ID = 'su']"); // click Baidu

}
}

 

Selenium --- encapsulation example

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.