SELENIUM2 launching the browser and loading the plugin

Source: Internet
Author: User

First, SELENIUM2 launch browser

Note: When launching the browser, SELENIUM2 is launching a clean browser without the task plugin and cookies, even if your previous browser has set up an agent, to the automatic startup, there is no proxy mode.

1. Start the Firefox browser:

Launch the Firefox browser that is not in the default installation path:

2. Launch the Chrome browser:

Requires Chromedriver.exe support, driver (http://docs.seleniumhq.org/download/)

If you do not want to use the SetProperty way, you can also put Chromedriver.exe in the "C:\Windows\System32" path and restart the computer

3. Start IE Browser:
Need IEDriverServer.exe support, and IE EXE file 64-bit and 32-bit, please choose the corresponding EXE file according to your own machine.
The startup code is as follows:

Ii. SELENIUM2 Loading plugin when launching browser

The role of loading plug-ins: There are some for debugging, but also some of the test system itself requires plug-ins

Firefox under load Firebug plugin:

Chrome under load CRX plugin:

And there is no plugin loaded under IE.


Iii. SELENIUM2 profile Setting when Firefox is started

Enter About:config in the Firefox address bar to see what you can set

Example: Address settings for export files


3. Enable the feature that is disabled by Firefox by default, with local events example, it is easy to set directly to true.

Especially important: When starting, every time is a clean Firefox, if you want to start the Firefox configuration of this machine:

If you want to start the Firefox configuration on machine A on machine B, pilot out A's configuration and load:

Copy the Profiles folder "C:\Users\cloudchen\AppData\Local\Mozilla\Firefox\Profiles" on the A machine.


Iv. SELENIUM2 profile settings when you start Chrome

Especially important: Copy the User Data folder "C:\Users\cloudchen\AppData\Local\Google\Chrome\User data"
?
Please verify for yourself that the difference between the following code is not added:


V. SELENIUM2 setting up when IE is started

Especially important: When you start IE, you need to turn off protection mode. The checkbox for Protected mode in 4 red-box marked areas is uncheck


? You can also code off:

  

The complete code is as follows:

Package Com.selenium.test;import Org.openqa.selenium.webdriver;import org.openqa.selenium.WebDriver.Navigation; Import Org.openqa.selenium.chrome.chromedriver;import Org.openqa.selenium.firefox.firefoxdriver;import Org.openqa.selenium.firefox.firefoxprofile;import Org.openqa.selenium.ie.internetexplorerdriver;public Class Launchbrowser {/** * @param args */public static void main (string[] args) {//TODO auto-generated method Stublaunchchrome ( );} public static void Launchfirefox () {firefoxprofile firefoxprofile = new Firefoxprofile (); Firefoxprofile.setpreference ( "Browser.download.folderList", 2); Firefoxprofile.setpreference ("Browser.download.manager.showWhenStarting", FALSE); Firefoxprofile.setpreference ("Browser.download.dir", "d:\\test"); Firefoxprofile.setpreference (" Browser.helperApps.neverAsk.saveToDisk "," text/csv "); String Proxyip = "child-prc.intel.com"; int proxyport = 913;firefoxprofile.setpreference ("Network.proxy.type", 1); Firefoxprofile.setpreference ("Network.proxy.http", Proxyip); Firefoxprofile.setpreference ("Network.proxy.http_port", ProxyPort); Firefoxprofile.setpreference (" Network.proxy.ssl ", Proxyip); Firefoxprofile.setpreference (" Network.proxy.ssl_port ", ProxyPort); Firefoxprofile.setpreference ("Network.proxy.share_proxy_settings", true); Firefoxprofile.setpreference (" network.proxy.no_proxies_on "," localhost "); Webdriver Driver = new Firefoxdriver (firefoxprofile);//Webdriver Driver = new Firefoxdriver (); Navigation Navigation = Driver.navigate () navigation.to ("https://baidu.com");//Driver.close ();//Driver = null;} public static void Launchchrome () {System.setproperty ("Webdriver.chrome.driver", "Files/chromedriver.exe"); Webdriver Driver = new Chromedriver (); Navigation Navigation = Driver.navigate () navigation.to ("https://www.baidu.com");d river.close ();d river = null;} public static void Launchie () {System.setproperty ("Webdriver.ie.driver", "Files/iedriver64.exe"); Webdriver Driver = new Internetexplorerdriver (); Navigation Navigation = Driver.navigate (); Navigation. to ("https://www.baidu.com");d river.close ();d river = null;}} 

SELENIUM2 launching the browser and loading the plugin

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.