Selenium-webdriverapi Interface Detailed

Source: Internet
Author: User

Ext.: http://www.imdsx.cn/index.php/2017/07/31/api/

Browser actions

# Refresh  #   forward  #  back driver.back ()

Get tag Element

#locating the target element by IDDRIVER.FIND_ELEMENT_BY_ID ('I1') #locating target elements by classnameDriver.find_element_by_class_name ('C1') #locating the target element through the Name propertyDriver.find_element_by_name ('N1') #locating target elements through XPathDriver.find_element_by_xpath ('//*[@id = "I1"]') #positioning target elements via CSS selectorDriver.find_element_by_css_selector ('#i1') #positioning by label name (note: In a page, the label must be repeated, so do not use this to locate)Driver.find_element_by_tag_name ('input') #find elements through text in a labelDriver.find_element_by_link_text ('Login') #find by fuzzy matching of text in labelsDriver.find_elements_by_partial_link_text ('Record')

Get tag elements commonly used a total of 8 positioning methods, and selenium actually provides 18 positioning methods, and 8 is the above plural form, here does not introduce, the actual use is not commonly used, there are 2 is actually the above said 16 of the underlying package. A method of invocation that is parameterized.

Cookie manipulation

#based on Cookiekey, get cookie informationCookie = Driver.get_cookie ('Cookiekey') #Get all cookie informationcookies =driver.get_cookies ()#Add a cookie, in strict accordance with the format, the cookie key is Name,value valueDriver.add_cookie ({'name':'tmp','value':'123123123'}) #Delete all cookie informationdriver.delete_all_cookies ()#Delete the corresponding cookie according to CookiekeyDriver.delete_cookie ('UICode')

Window operations

#gets the size of the current browserdriver.get_window_size ()#set the browser size by pixelDriver.set_window_size ('width','Height') #gets the coordinates of the current window's location for Windows x, ydriver.get_window_position ()#sets the location of the current window for Windows, x, yDriver.set_window_position (20,20) #maximizes the current window without the need for a pass parameterDriver.maximize_window ()#returns the browser handle for the current operationDriver.current_window_handle#returns all browser handles for open serverDriver.window_handles

Intercept current Page

# To get the binary picture data of the current page, you need to write the file yourself  #  as_png in the upper package, only need to pass in the image name automatically written picture driver.get_screenshot_as_file ('  Filename.png')

Executing javascript statements

# execute JavaScript statement driver.execute_script ('javascript commond'# Example: # using JS to manipulate the scroll bar # parameter 1:x  parameter 2:ywindow.scrollto (100,400);

Close and exit

# Close the current page when multiple is turned on  #  exit and close all page drivers driver.quit ()

Other

# back to page source code  #  return tag title  #  returns the current URL#  get browser name such as: Chrome Driver.name

Elementapi interface

#gets the property value based on the Label property nameElement.get_attribute ('style') #enter a string into the input box if the type of input is a file type, you can enter an absolute path to upload the fileElement.send_keys ()#Clear Text contentelement.clear ()#left mouse button click OperationElement.click ()#Get Properties by property nameElement.get_property ('ID') #returns whether the element is visible True or Falseelement.is_displayed ()#returns whether the element is selected True or Falseelement.is_selected ()#returns the name of the label elementElement.tag_name#Gets the width and height of the current labelelement.size#get the text content of an elementElement.text#Copy the return button to submit the dataElement.submit ()#gets the coordinates of the current elementelement.location#Capturing PicturesElement.screenshot ()

Common exceptions

Nosuchelementexception: No element found nosuchframeexception: No iframe found nosuchwindowexception: Window handle not found handle Nosuchattributeexception: Property Error noalertpresentexception: No alert popup found Elmentnotvisibleexception: element not visible Elementnotselectableexception: Element not selected timeoutexception: Find element timeout

Selenium-webdriverapi Interface Detailed

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.