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