selenium common method set

8 ways .selenium a positioning element:

   1.find_element_by_id()

   2.find_element_by_name()

        3.find_element_by_css()

        4.find_element_by_xpath()

        5.find_element_by_tag_name()

   6.find_element_by_class_name()

        7.find_element_by_partial_link_text()

   8.find_element_by_link_text()

 

II. Browser operation

  1.maximize_window () window is maximized

  2.refresh () to refresh the current page

  3.forward () forward

  4.back () Back

 

III. Elements for operation

  1.clear () Clears the contents of the text box

  2.send_keys () typing

  3.click () Click

  4.size returns the size of the element

  5.text return text elements

  6.get_attribute (name) to obtain properties of the elements

  7.is _displayed () Gets element is visible

  8.title get the title of the current page

  9.current_url obtain the URL of the current page

 

IV. Multi-Form switch

  1.switch_to_frame () default can fill out the form id or name

  2.switch_to.default_content () jump back to the outermost layer of the page

 

V. multi-window switch

  1.switch_to_window()  

webdriver the Selenium Import from 
Import Time 

Driver = webdrive.Firefox () 
driver.get ( 'http://www.baidu.com') 

# get Baidu search window handle 
search_windows = driver.current_window_handle 

driver.find_element_by_link_text ( 'login') .click () 
driver.find_element_by_link_text ( 'Sign up now') .click () 

# get the current open windows of all handles 
all_handles = driver.window_handles () 

# to enter the registration window 
for handle in all_handles: 
  ! IF handle = search_windows: 
    driver.switch_to. window (handle) 
    ...... 
# return to the search window 
for handle in all_handles: 
  IF handle == search_windows: 
    driver.switch_to.window (handle) 
    ......

 VI. Warning processing frame (JavaScript generated alert, confrim and prompt)

  1.switch_to_alert().text

  2.switch_to_alert().accept()

  3.switch_to_alert().dismiss()

  4.switch_to_alert().send_keys()

VII. Operation cookie

  1.get_cookies()

  2.get_cookie (name) Returns the name of the dictionary key is the cookie object

  3.add_cookie (cookie_dict) click on the cookie, cookie_dict refers to the dictionary objects

  4.delete_cookie (name, optionsString) delete the cookie information

  5.delete_all_cookies delete all cookie information

 

VIII. Screenshot of the window

  driver.get_screenshot_as_file("c:/cale/report/1.jpg")

 

IX. Close

  driver.close()

 

X. Close the browser

  driver.quite()

 

  

Guess you like

Origin www.cnblogs.com/pipile/p/12581464.html