1. Enter the input box
Input: sendKeys ();
Clear: clear ();
Click on: click ();
In order to ensure accurate input results, in general, to empty, and then enter
2. button button
Click on: click ();
determining whether elements can visit: isEnable ();
submit the form:, submit (); click ( ) can also be used, sometimes an error
3. Upload file
sendKeys ( "c: \\ 1.jpg"); parameter file path
4. The radio button, checkbox
the Click (); elected
Clear (); cancel chosen
isSelected (); determining whether optional
The drop-down selection box
Select new object interface elements as parameters: Select select = new Select (element);
Selection value
Index-: select.selectByIndex (int index);
according to the value argument: select.selectByValue (String value);
by visible text: select.selectByVisibleText (String text);
Traverse the drop-down menu
Select select = new Select(driver.findElement(By.id("idValue"))); for(WebElement e : select.getOptions()) e.click(); }
6. mouse, using class Actions
WebElement input=driver.findElement(By.id("su")); Actions action=new Actions(driver);
Click: action.click (input) .perform ();
双击:action.doubleClick(input).perform();
右击:action.contextClick((input).perform();
Hover: action.moveToElement (input) .perform ();
拖动:action.dragAndDrop((input).perform();
Pressing the left mouse button on an element: action.click_and_hold ((input) .perform ();
Note: Method Class Actions must end with perform (), or will not perform
7. keyboard
To delete a character:. Driver.findElement (By.xpath ( "// * [@ id = 'kw']")) sendKeys (Keys.BACK_SPACE)
输入“m”:driver.findElement(By.xpath("//*[@id='kw']")).sendKeys("m");
Enter a space: driver.findElement (By.xpath ( "// * [@ id = 'kw']")) sendKeys (Keys.SPACE);.
Select input box content: driver.findElement (By.xpath ( "// * [@ id = 'kw']")) sendKeys (Keys.CONTROL, "a");.
复制:driver.findElement(By.xpath("//*[@id='kw']")).sendKeys(Keys.CONTROL,"c");
Shear input box content: driver.findElement (By.xpath ( "// * [@ id = 'kw']")) sendKeys (Keys.CONTROL, "x");.
Paste input box content: driver.findElement (By.xpath ( "// * [@ id = 'kw']")) sendKeys (Keys.CONTROL, "v");.
. Enter instead submit operation by: driver.findElement (By.xpath ( "// * [@ id = 'kw']")) sendKeys (Keys.ENTER);