Package test;
Import Org.openqa.selenium.By;
Import org.openqa.selenium.Dimension;
Import Org.openqa.selenium.WebDriver;
Import Org.openqa.selenium.firefox.FirefoxDriver;
Import Net.sourceforge.htmlunit.corejs.javascript.tools.debugger.Main;
public class Test {
public static void Main (string[] args) {
System.setproperty ("Webdriver.gecko.driver", "D:/firefox-47.0.1.win64.sdk/firefox-sdk/bin/geckodriver.exe");
For selenium3.0 above need to introduce gecko.driver, to normal operation.
Webdriver drive = new Firefoxdriver ();
Drive.manage (). window (). SetSize (New Dimension (500, 1000));
Set browser width and height
Drive.manage (). window (). Maximize ();
Maximize your browser
Drive.get ("https://www.baidu.com");
Open Baidu website
Drive.navigate (). back ();
Back off
Drive.navigate (). Forward ();
Forward, here the page should return with Baidu page
Drive.navigate (). Refresh ();
Refreshes the Web page.
Drive.findelement (By.id ("kw")). Clear ();
Clear the text in the input box
Drive.findelement (By.id ("kw")). SendKeys ("Selenium");
Enter selenium into the Baidu text box
Drive.findelement (By.id ("su")). Click ();
Click the Search Submit button
Drive.findelement (By.id ("su")). Submit ();
Here the Submit () method is consistent with the click () method, and submit () is used to submit the form.
System.out.println (Drive.findelement (by.id ("kw")). GetSize ());
Gets the size (width, height) of the text box where the element is located
System.out.println (Drive.findelement (by.id ("su")). GetText ());
System.out.println (Drive.findelement (by.id ("su")). GetAttribute ("value"));
System.out.println (Drive.findelement (by.id ("kw")). isdisplayed ());
Determine if an element exists
}
}
Selenium Common browser Operation API