WebDriver API: Controls browser details and webdriverapi

Source: Internet
Author: User

WebDriver API: Controls browser details and webdriverapi

WebDriver mainly provides the operation pageVarious elementsBut it also providesBrowser operationsMethods, such as controlling the browser size, operating the browser forward and backward.

(1) control the browser window size driver. manage (). window (). setSize (new Dimension (480,800); driver. manage (). window (). maximize ();

Sometimes we want to open it in a browser size, and the accessed page will run in this size. For example, you can set the browser size to 480*800 on the mobile terminal, visit the mobile site, and evaluate its style;
WebDriver providesSet_window_size ()Method To set the browser size. In most cases, if you want the browser to execute the automated test script on the PC end in full screen mode, you can use the maximize () method to enable full screen display of the opened browser. Its usage and setSize () same, but it does not need any parameters.

// Browser. javapackage com. mypro. jase; import org. openqa. selenium. dimension; import org. openqa. selenium. webDriver; import org. openqa. selenium. chrome. chromeDriver; public class Browser {public static void main (String [] args) {System. out. println ("seting brwoser"); WebDriver driver = new ChromeDriver (); driver. manage (). window (). setSize (new Dimension (480,800); // set the size of the browser to 480*800 driver on the mobile terminal. get ("https://m.mail.10086.cn"); driver. quit ();}}
(2) control the browser to move back and forward. driver. navigate (). back (); driver. navigate (). forward ();

When you use a browser to browse a webpage, the browser provides the back and forward buttons to conveniently switch between browsed webpages. The WebDriver also provides the correspondingBack ()AndForward ()Method to simulate the backward and forward buttons

// BrowserGo. javapackage com. mypro. jase; import org. openqa. selenium. webDriver; import org. openqa. selenium. chrome. chromeDriver; public class BrowserGo {public static void main (String [] args) {WebDriver driver = new ChromeDriver (); String firstUrl =" https://www.baidu.com "; System. out. printf (" now accesss % s \ n ", firstUrl); driver. get (firstUrl); String secondUrl =" https://news.baidu.com"; System. out. printf ("now accesss % s \ n", secondUrl); driver. get (secondUrl); System. out. printf ("now back to % s \ n", firstUrl); driver. navigate (). back (); System. out. printf ("forward to % s \ n", secondUrl); driver. navigate (). forward (); driver. quit () ;}// output result: ------------------------------------------------------------- broser back and forward. starting ChromeDriver 2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1) on port 20680 Only local connections are allowed. january 07 6:17:30 org. openqa. selenium. remote. protocolHandshake createSession information: Detected dialect: OSSnow access: https://www.baidu.com Now access: https://news.baidu.comNow back: https://www.baidu.com Now back: https://news.baidu.com
(3) simulate browser refresh

Driver. navigate (). refresh ();

 

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.