Java programming language Selenium drive each browser code

Source: Internet
Author: User

Here is the Selenium3.7 version, first introduced in the Windows environment to run;

Summary of the following considerations:

1. Set the driver path for each browser

System.setproperty ("," "");

2, create a browser object

Webdriver driver = new xxx ();

1. Drive IE Browser

IE Browser driver has 32-bit and 64-bit, two versions, recommended to use 32 iedriver, because the 64-bit IE driver run up too slow

1  PackageBase;2 3 ImportJava.util.concurrent.TimeUnit;4 ImportOrg.openqa.selenium.WebDriver;5 ImportOrg.openqa.selenium.ie.InternetExplorerDriver;6 7  Public classTestiedriver {8 9      Public Static voidMain (String args[])throwsinterruptedexception {Ten  OneSystem.setproperty ("Webdriver.ie.driver", ". \\Tools\\IEDriverServer.exe"); AWebdriver Driver =Newinternetexplorerdriver (); - driver.manage (). window (). Maximize (); -Driver.get ("http://www.baidu.com"); theString s =driver.gettitle (); - System.out.print (s); -Driver.manage (). Timeouts (). Implicitlywait (10, timeunit.seconds); -Thread.Sleep (1000); + driver.close (); -  +     } A}

2. Drive Chrome Browser

1  PackageBase;2 3 Importjava.util.Arrays;4 ImportJava.util.concurrent.TimeUnit;5 6 ImportOrg.openqa.selenium.WebDriver;7 ImportOrg.openqa.selenium.chrome.ChromeDriver;8 Importorg.openqa.selenium.chrome.ChromeOptions;9 Importorg.openqa.selenium.remote.DesiredCapabilities;Ten  One  Public classTestchromedriver { A  -      Public Static voidMain (String args[])throwsinterruptedexception { -  theSystem.setproperty ("Webdriver.chrome.driver", ". \\Tools\\chromedriver.exe"); -Chromeoptions options =Newchromeoptions (); -Desiredcapabilities capabilities =desiredcapabilities.chrome (); -Capabilities.setcapability ("Chrome.switches", Arrays.aslist ("--start-maximized")); +Options.addarguments ("--test-type", "--start-maximized"); -Webdriver Driver =Newchromedriver (options); +Driver.get ("http://www.baidu.com"); A  atDriver.manage (). Timeouts (). Implicitlywait (10, timeunit.seconds); -Thread.Sleep (1000); - driver.close (); -  -     } -  in}

3. Drive Firefox Firefox browser

1  PackageBase;2 3 ImportJava.util.concurrent.TimeUnit;4 5 ImportOrg.openqa.selenium.WebDriver;6 ImportOrg.openqa.selenium.firefox.FirefoxDriver;7 8  Public classTestfirefoxdriver {9 Ten      Public Static voidMain (String args[])throwsinterruptedexception { One  ASystem.setproperty ("Webdriver. Firefox.driver ",". \\Tools\\geckodriver.exe "); -Webdriver Driver =Newfirefoxdriver (); - driver.manage (). window (). Maximize (); theDriver.get ("http://www.baidu.com"); -String s =driver.gettitle (); - System.out.print (s); -Driver.manage (). Timeouts (). Implicitlywait (10, timeunit.seconds); +Thread.Sleep (1000); - driver.close (); +  A     } at  -}

Java programming language Selenium drive individual browser code

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.