Selenium Test (Java)--Browser Control

Source: Internet
Author: User

1. Control browser window Size

1  PackageCom.test.window;2 3 Importorg.openqa.selenium.Dimension;4 ImportOrg.openqa.selenium.WebDriver;5 ImportOrg.openqa.selenium.firefox.FirefoxDriver;6 7  Public classWindowSize {8 9      Public Static voidMain (string[] args) {Ten Webdriver driver; One         //Get driver ADriver =Newfirefoxdriver (); -Driver.get ("http://www.baidu.com/"); -         //Maximize the screen the driver.manage (). window (). Maximize (); -WaitTime (3000); -  -         //set Browser Size to width 800, high 480 +         Dimension arg0 = new Dimension (480);  driver.manage (). window (). setSize (arg0);  +WaitTime (3000); A  at driver.quit (); -     } -  -     Static  Public voidWaitTime (intTime ) { -  -         Try { in Thread.Sleep (time); -}Catch(interruptedexception e) { to             //TODO auto-generated Catch block + e.printstacktrace (); -         } the     } *}

2. Control browser forward and backward

1  PackageCom.test.window;2 3 ImportOrg.openqa.selenium.WebDriver;4 ImportOrg.openqa.selenium.firefox.FirefoxDriver;5 6  Public classWindowbackandforward {7 8      Public Static voidMain (string[] args) {9         //TODO auto-generated Method StubTen  OneWebdriver Driver =Newfirefoxdriver (); A          -         //Enter Baidu homepage -Driver.get ("http://www.baidu.com"); the driver.manage (). window (). Maximize (); -WaitTime (3000); -         //Enter Baidu News -Driver.get ("http://news.baidu.com"); +WaitTime (3000); -         //back to Baidu homepage + driver.navigate (). back (); AWaitTime (3000); at         //forward to Baidu News - driver.navigate (). Forward (); -WaitTime (3000); -          - driver.quit (); -     } in      -     Static  Public voidWaitTime (intTime ) { to          +         Try { - Thread.Sleep (time); the}Catch(interruptedexception e) { *             //TODO auto-generated Catch block $ e.printstacktrace ();Panax Notoginseng         } -     } the  +}

3. Simulate browser refresh

1  PackageCom.test.window;2 3 ImportOrg.openqa.selenium.WebDriver;4 ImportOrg.openqa.selenium.firefox.FirefoxDriver;5 6  Public classWindowrefresh {7 8      Public Static voidMain (string[] args) {9Webdriver Driver =Newfirefoxdriver ();Ten  OneDriver.get ("http://news.baidu.com"); A driver.manage (). window (). Maximize (); -WaitTime (3000); -  the         //Refresh - driver.navigate (). Refresh (); -WaitTime (3000); -              + driver.quit (); -  +     } A  at     Static  Public voidWaitTime (intTime ) { -  -         Try { - Thread.Sleep (time); -}Catch(interruptedexception e) { -             //TODO auto-generated Catch block in e.printstacktrace (); -         } to     } +  -}

Selenium Test (Java)--Browser Control

Related Article

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.