Selenium+python Browser Call: Firefox__python

Source: Internet
Author: User
Tags in python
How to view the Python Selenium API

Python-m pydoc-p 4567

Description

Python-m Pydoc represents opening the Pydoc module, Pydoc is the preferred tool for viewing Python documents;

-p 4567 means start the server on port 4567

Then access http://localhost:4567/in the browser, you should see all modules in Python by ctrl+f, enter selenium, navigate to the link to the selenium document, and click Enter to http:// Localhost:4567/selenium.html this page

This is where the selenium document is located, and then you can view it as you want it to. For example, if you want to view the basic methods of the Webdriver class, you can access this page http://localhost:4567/selenium.webdriver.remote.webdriver.html Firefox browser calls Firefox browser driver add

Firefox native support, no need to download the driver, as long as the browser can be installed to the Firefox browser calls

#coding =utf-8 from
Selenium import webdriver

driver=webdriver. Firefox ()
url= ' http://www.baidu.com '
driver.get (URL)
driver.close ()

Description

1, "#coding =utf-8" in order to prevent the garbled problem, in order to add Chinese annotation in the program, the code for UTF-8, note = two times do not leave blank, otherwise it does not work, and "#_ *_coding:utf-8_*_" can also achieve the same effect

2, "From Selenium import Webdriver" This step is to import the Selenium Webdriver package, only import selenium package, we can use the Webdriver API for automated scripting development

3, "Driver=webdriver." Firefox () "Here will control the webdriver of Firefox assigned to driver, through the driver to get the browser to manipulate the object, you can start the browser, open the URL, the corresponding page elements of the operation." you need to start a fixed plugin in your Firefox auto run

First of all, according to the above browser call, Webdriver launched the browser, launched a clean without tasks, plug-ins and Cookies information browser (even if you have a local Firefox installed some plug-ins, Webdriver startup Firefox is not the plugin) , but it is possible to test the system itself requires plug-ins or need to debug and so on, the script will not be able to run the card, then how to solve it. Before you answer the question, learn how to customize Firefox with a specific configuration. Customizing the Firefox configuration file

The steps are as follows:

1. Run cmd, open Firefox Profile Manager

2. Click "Create profile ..." To complete the steps, including entering the profile name

3. Click "Start Firefox"

4. Install your own add-on or other configuration in the newly-launched Firefox

Attached: Java code:

String spath = @ "C:\Users\xxxx\AppData\Roaming\Mozilla\Firefox\Profiles\5f3xae4a.default"; Firefoxprofile ffprofile = new Firefoxprofile (spath); method One: Use the custom Firefox profile

When you use Webdriver to drive Firefox browser, if you do not set parameters, the default use of the Firefox profile and the usual browser to open the use of Firefox is not the same, if you want to use the usual configuration, you need to increase the following operations:

Profile_dir= "C:\Users\admin\AppData\Roaming\Mozilla\Firefox\Profiles\wrdjxgdk.default-1434681389856"
Profile = Webdriver. Firefoxprofile (profile_dir)
driver = Webdriver. Firefox (Profile)

Add the above configuration, then call driver for get operation, where the yellow background part of the Firefox prifiles file directory, generally in: C:\Users\admin\AppData\Roaming\Mozilla\Firefox\ Profiles directory, as to what kind of browser to start, can be defined according to their needs, such as:

A. Browsing the web, the plug-ins that must be installed are installed and set to: Always activate

B. Necessary security settings methods Two: Configuring with code

This method is directly inside the code for plug-in installation and profile configuration, the following example Firebug plug-in calls:

Profile=webdriver. Firefoxprofile ()
#加载插件
profile.add_extension (' c:\\firebug-2.0.8-fx.xpi ') 
#激活插件        
Profile.set_preference ("Extensions.firebug.allPagesActivation", "on") Driver=webdriver. Firefox (Profile)

After adding the above configuration, call driver for a get operation.

In addition to using the method mentioned above to customize the plugin, Webdriver can also be customized profile (in the Firefox address bar to enter About:config, you can view the Firefox parameters), the following example set the proxy and default download path:

myweb= "192.168.9.111"
myport= "8080"

profile=webdriver. Firefoxprofile ()
#设置代理
profile.set_preference ("Network.proxy.type", 1)
profile.set_preference (" Network.proxy.http ", MyWeb)
profile.set_preference (" Network.proxy.http_port ", MyPort)
#设置文件下载目录
Profile.set_preference ("Browser.download.folderList", 2)
profile.set_preference ("Browser.download.dir", "C : \\test ")
driver=webdriver. Firefox (Profile)

Add the above configuration, then call driver for Get Operation reference

[1] SELENIUM2 (Webdriver) Summary (i)---Start the browser, set the profile& load plug-in,

Http://www.cnblogs.com/puresoul/p/4251536.html

[2] Webdriver runs the test using a custom Firefox profile,

http://lijingshou.iteye.com/blog/2085276

[3] Record the selenium problems I encountered,

http://blog.csdn.net/old_imp/article/details/11417999


Original address: http://www.cnblogs.com/leeboke/articles/5013711.html

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.