Selenium2+python Automation 27-View Selenium API

Source: Internet
Author: User
Tags deprecated tag name xpath

Objective

The front is a little bit of introduction selenium some of the API usage, then selenium API in the end how much? This article is called everyone How to check the Selenium API, do not ask for help, do not need to reach for someone, in their own computer there.

Pydoc is a python-brought module that is used to automatically generate documents from Python modules that can be rendered on text-based, web pages, and in a browser on the server!

First, Pydoc

1. What is Pydoc? , this is an accurate explanation: documentation generator and online Help system. Pydoc is a python-brought module that is used to automatically generate documents from Python modules that can be rendered on text-based, web pages, and in a browser on the server! In short, it's a tool that helps you automatically generate documents from code and annotations.

2. For a chestnut, I need to see the function and syntax of the open function in Python, open cmd, enter: Python-m Pydoc Open

3.-m parameter: Python runs the module as a scripting method

>>python-m Pydoc Open

So the problem is, this is already known to have this function, to see its function, selenium inside do not know how many functions or methods, how to view it?

Second, start the server

1. Open the cmd command line, enter: Python-m pydoc-p 6666

2.-p parameter: This indicates that the service is started on this machine

3.6666 parameter: This is the service port number, arbitrarily set

After opening, the interface will appear an address: http://localhost:6666/, open directly in the browser

Third, the browser to view the document

1. In the browser input: http://localhost:6666/

2.built-in Moudles: This is Python's own module.

Iv. Webdriver API

1. Find this path: python2.7\lib\site-packages, open Selenium

2. Open Selenium>webdriver>firefox>webdriver, final path: http://localhost:6666/selenium.webdriver.firefox.webdriver.html

3. These are the Selenium Webdriver API help documentation.

Add_cookie (self, cookie_dict)
Adds a cookie to your the current session.

: Args:
-Cookie_dict:a Dictionary object, with required keys-"name" and "value";
Optional Keys-"path", "Domain", "secure", "expiry"

Usage:
Driver.add_cookie ({' name ': ' foo ', ' value ': ' Bar '})
Driver.add_cookie ({' name ': ' foo ', ' value ': ' Bar ', ' path ': '/'})
Driver.add_cookie ({' name ': ' foo ', ' value ': ' Bar ', ' path ': '/', ' Secure ': True})

Back (self)
Goes one step backward in the browser.

: Usage:
Driver.back ()

Close (self)
Closes the current window.

: Usage:
Driver.close ()

Create_web_element (self, element_id)
Creates a Web element with the specified element_id.

Delete_all_cookies (self)
Delete all cookie in the scope of the session.

: Usage:
Driver.delete_all_cookies ()

Delete_cookie (self, name)
Deletes a single cookie with the given name.

: Usage:
Driver.delete_cookie (' My_cookie ')

Execute (Self, driver_command, Params=none)
Sends a command to being executed by a command.commandexecutor.

: Args:
-Driver_command:the name of the command to execute as a string.
-Params:a Dictionary of named parameters to send with the command.

: Returns:
The command ' s JSON response loaded into a Dictionary object.

Execute_async_script (self, script, *args)
Asynchronously executes JavaScript in the current window/frame.

: Args:
-Script:the JavaScript to execute.
-\*args:any applicable arguments for your JavaScript.

: Usage:
Driver.execute_async_script (' Document.title ')

Execute_script (self, script, *args)
synchronously executes JavaScript on the current window/frame.

: Args:
-script:the JavaScript to execute.
-\*args:any applicable arguments for your JavaScript.

: Usage:
Driver.execute_script (' document.title ')

File_detector_context (*args, **kwds)
Overrides the current file detector (if necessary) in limited context.
Ensures the original file detector is set afterwards.

Example:

With Webdriver.file_detector_context (uselessfiledetector):
Someinput.send_keys ('/etc/hosts ')

: Args:
-File_detector_class-class of the desired file detector. If the class is different
From the current file_detector, then the class was instantiated with args and Kwargs
and used as a file detector during the duration of the context manager.
-Args-optional arguments that get passed to the file detector class during
Instantiation.
-Kwargs-keyword arguments, passed the same as args.

Find_element (self, by= ' id ', value=none)
' Private ' method used by the find_element_by_* methods.

: Usage:
Use the corresponding find_element_by_* instead of this.

: rtype:webelement

Find_element_by_class_name (self, name)
Finds an element by class name.

: Args:
-Name:the class name of the element to find.

: Usage:
Driver.find_element_by_class_name (' foo ')

Find_element_by_css_selector (self, css_selector)
Finds an element by CSS selector.

: Args:
-Css_selector:the CSS Selector to use when finding elements.

: Usage:
Driver.find_element_by_css_selector (' #foo ')

find_element_by_id (self, id_)
Finds an element by ID.

: Args:
-Id\_-The ID of the element to be found.

: Usage:
driver.find_element_by_id (' foo ')

Find_element_by_link_text (self, link_text)
Finds an element by link text.

: Args:
-Link_text:the text of the element to be found.

: Usage:
Driver.find_element_by_link_text (' Sign in ')

Find_element_by_name (self, name)
Finds an element by name.

: Args:
-name:the name of the element to find.

: Usage:
Driver.find_element_by_name (' foo ')

Find_element_by_partial_link_text (self, link_text)
Finds an element is a partial match of its link text.

: Args:
-Link_text:the text of the element to partially match on.

: Usage:
Driver.find_element_by_partial_link_text (' sign ')

Find_element_by_tag_name (self, name)
Finds an element by tag name.

: Args:
-Name:the tag name of the element to find.

: Usage:
Driver.find_element_by_tag_name (' foo ')

Find_element_by_xpath (self, XPath)
Finds an element by XPath.

: Args:
-Xpath-the XPath Locator of the element to find.

: Usage:
Driver.find_element_by_xpath ('//div/td[1] ')

Find_elements (self, by= ' id ', value=none)
' Private ' method used by the find_elements_by_* methods.

: Usage:
Use the corresponding find_elements_by_* instead of this.

: Rtype:list of Webelement

Find_elements_by_class_name (self, name)
Finds elements by class name.

: Args:
-Name:the class name of the elements to find.

: Usage:
Driver.find_elements_by_class_name (' foo ')

Find_elements_by_css_selector (self, css_selector)
Finds elements by CSS selector.

: Args:
-Css_selector:the CSS Selector to use when finding elements.

: Usage:
Driver.find_elements_by_css_selector ('. Foo ')

find_elements_by_id (self, id_)
Finds multiple elements by ID.

: Args:
-Id\_-The ID of the elements to be found.

: Usage:
driver.find_elements_by_id (' foo ')

Find_elements_by_link_text (self, text)
Finds elements by link text.

: Args:
-link_text:the text of the elements to be found.

: Usage:
Driver.find_elements_by_link_text (' Sign in ')

Find_elements_by_name (self, name)
Finds elements by name.

: Args:
-name:the name of the elements to find.

: Usage:
Driver.find_elements_by_name (' foo ')

Find_elements_by_partial_link_text (self, link_text)
Finds elements by a partial match of their link text.

: Args:
-Link_text:the text of the element to partial match on.

: Usage:
Driver.find_element_by_partial_link_text (' sign ')

Find_elements_by_tag_name (self, name)
Finds elements by tag name.

: Args:
-name:the tag name the use when finding elements.

: Usage:
Driver.find_elements_by_tag_name (' foo ')

Find_elements_by_xpath (self, XPath)
Finds multiple elements by XPath.

: Args:
-Xpath-the XPath Locator of the elements to be found.

: Usage:
Driver.find_elements_by_xpath ("//div[contains (@class, ' foo ')]")

Forward (self)
Goes one step forward in the browser.

: Usage:
Driver.forward ()

Get (self, URL)
Loads a Web page in the current browser session.

Get_cookie (self, name)
Get a single cookie by name. Returns the cookie if found, None if not.

: Usage:
Driver.get_cookie (' My_cookie ')

Get_cookies (self)
Returns a set of dictionaries, corresponding to cookie visible in the current session.

: Usage:
Driver.get_cookies ()

Get_log (self, log_type)
Gets the log for a given log type

: Args:
-Log_type:type of log that which'll be returned

: Usage:
Driver.get_log (' browser ')
Driver.get_log (' driver ')
Driver.get_log (' client ')
Driver.get_log (' server ')

Get_screenshot_as_base64 (self)
Gets the screenshot of the current window as a Base64 encoded string
Which is useful in embedded images in HTML.

: Usage:
Driver.get_screenshot_as_base64 ()

Get_screenshot_as_file (self, filename)
Gets the screenshot of the current window. Returns False If there is
Any IOError, else returns TRUE. Use full paths in your filename.

: Args:
-Filename:the full path, wish to save your screenshot to.

: Usage:
Driver.get_screenshot_as_file ('/screenshots/foo.png ')

Get_screenshot_as_png (self)
Gets the screenshot of the current window as a binary data.

: Usage:
Driver.get_screenshot_as_png ()

Get_window_position (self, windowhandle= ' current ')
Gets the x, y position of the current window.

: Usage:
Driver.get_window_position ()

Get_window_size (self, windowhandle= ' current ')
Gets the width and height of the current window.

: Usage:
Driver.get_window_size ()

Implicitly_wait (self, time_to_wait)
Sets a sticky timeout to implicitly wait for an element to be found,
or a command to complete. This method is only needs to be called one
Time per session. To set the timeout for calls to
Execute_async_script, see Set_script_timeout.

: Args:
-Time_to_wait:amount of Time to wait (in seconds)

: Usage:
Driver.implicitly_wait (30)

Maximize_window (self)
Maximizes the current window, Webdriver is using

Refresh (self)
Refreshes the current page.

: Usage:
Driver.refresh ()

Save_screenshot = Get_screenshot_as_file (self, filename)
Gets the screenshot of the current window. Returns False If there is
Any IOError, else returns TRUE. Use full paths in your filename.

: Args:
-Filename:the full path, wish to save your screenshot to.

: Usage:
Driver.get_screenshot_as_file ('/screenshots/foo.png ')

Set_page_load_timeout (self, time_to_wait)
Set The amount of time to wait for a page load to complete
Before throwing an error.

: Args:
-Time_to_wait:the amount of time to wait

: Usage:
Driver.set_page_load_timeout (30)

Set_script_timeout (self, time_to_wait)
Set The amount of time, the script should wait during an
Execute_async_script call before throwing an error.

: Args:
-Time_to_wait:the amount of time to wait (in seconds)

: Usage:
Driver.set_script_timeout (30)

Set_window_position (self, x, y, windowhandle= ' current ')
Sets the x, y position of the current window. (Window.moveto)

: Args:
-X:the x-coordinate in pixels to set the window position
-Y:the y-coordinate in pixels to set the window position

: Usage:
Driver.set_window_position (0,0)

Set_window_size (self, width, height, windowhandle= ' current ')
Sets the width and height of the current window. (Window.resizeto)

: Args:
-width:the width in pixels to set the window to
-height:the height in pixels to set the window to

: Usage:
Driver.set_window_size (800,600)

Start_client (self)
Called before starting a new session. This method is overridden
To define custom startup behavior.

Start_session (self, desired_capabilities, Browser_profile=none)
Creates a new session with the desired capabilities.

: Args:
-browser_name-the name of the browser to request.
-Version-which browser version to request.
-Platform-which platform to request the browser on.
-Javascript_enabled-whether The new session should support JavaScript.
-Browser_profile-a Selenium.webdriver.firefox.firefox_profile. Firefoxprofile object. Only used if Firefox is requested.

Stop_client (self)
Called after executing a quit command. This method is overridden
To define custom shutdown behavior.

Switch_to_active_element (self)
Deprecated Use Driver.switch_to.active_element

Switch_to_alert (self)
Deprecated Use Driver.switch_to.alert

Switch_to_default_content (self)
Deprecated Use Driver.switch_to.default_content

Switch_to_frame (self, frame_reference)
Deprecated Use Driver.switch_to.frame

Switch_to_window (self, window_name)
Deprecated Use Driver.switch_to.window

Data descriptors inherited from Selenium.webdriver.remote.webdriver.WebDriver:

__dict__
Dictionary for instance variables (if defined)

__weakref__
List of weak references to the object (if defined)

Application_cache
Returns a Applicationcache Object to interact with the browser app cache

Current_url
Gets the URL of the current page.

: Usage:
Driver.current_url

Current_window_handle
Returns the handle of the current window.

: Usage:
Driver.current_window_handle

Desired_capabilities
Returns the drivers current desired capabilities being used

File_detector

Log_types
Gets a list of the available log types

: Usage:
Driver.log_types

Mobile

Name
Returns the name of the underlying browser for this instance.

: Usage:
-Driver.name

Orientation
Gets the current orientation of the device

: Usage:
Orientation = driver.orientation

Page_source
Gets the source of the current page.

: Usage:
Driver.page_source

Switch_to

Title
Returns the title of the current page.

: Usage:
Driver.title

Window_handles
Returns the handles of all windows within the current session.

: Usage:
Driver.window_handles

Selenium2+python Automation 27-View Selenium API

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.