Java Selenium Operation Browser instance _java

Source: Internet
Author: User

This article describes the selenium Operation browser

Reading Table of Contents

    1. Browser maximize forward, back, refresh
    2. Screenshot operation
    3. Simulate mouse operation
    4. Kill Windows Browser Process

Browser maximize forward, back, refresh

public static void Testbrowser (Webdriver driver) throws Exception
  {
    driver.get ("http://www.cnblogs.com/ Tankxiao ");
    Thread.Sleep (5000);
    Browser maximization
    driver.manage (). window (). Maximize ();
    
    Driver.navigate () to ("http://www.baidu.com");
    Refresh Browser
    driver.navigate (). Refresh ();
    Browser backward
    driver.navigate (). back ();
    Browser forward
    Driver.navigate (). Forward ();
    Browser exit
    driver.quit ();
  }

Screenshot operation

 public static void Testscreenshot (Webdriver driver) throws Exception
  {
    driver.get ("http://www.baidu.com");
    File srcfile = ((takesscreenshot) driver). Getscreenshotas (outputtype.file);
    Fileutils.copyfile (Srcfile, New File ("C:\\1.png"));
  }
 

Simulate mouse operation

public static void Rightclickmouse (Webdriver driver)
  {
    driver.get ("http://www.baidu.com");
    Actions action = new actions (driver);
    
    Action.contextclick (Driver.findelement (by.id ("kw")). Perform ();  
  

Kill Windows Browser Process

 public static void KillProcess ()
  {
    //kill Firefox
    windowsutils.trytokillbyname ("Firefox.exe");
    Kill IE
    Windowsutils.trytokillbyname ("Iexplore.exe");
    Kill Chrome
    Windowsutils.trytokillbyname ("Chrome.exe");
  }

Above is the Java Selenium Data collation, follow-up continue to add, thank you for your support of this site!

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.