Selenium Common browser Operation API

Source: Internet
Author: User

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

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.