python + selenium study notes

1. selenium in webdriver module browser

  1) browser = webdriver.Firefox () # open the browser

  2) browser.get (URL) # open a web page

  3) browser.title, current_url # determine whether access failure

      4) ele = browser.find_element_by_id () / name () # positioning element

  5) ele.clear () # Empty

  6) (arg) # input value ele.send_keys

  7) ele.click () # Click

  8) ele.submit # submit the form

  9) browser.back () # return to the previous page

  10) browser.quit () # close the browser

 

2.webdriver browser module operates: Element Positioning

  1)browser.find_element_by_id/name()

  2) browser.find_element_by_xpath

  3) find_element_by_link_text

  4) find_element_by_partial_link_text

  5) find_element_by_tag_name

  6) find_element_by_class_name

  7) find_element_by_css_selector

 

3. simulate user behavior: mouse and keyboard events

  1)from selenium.webdriver.common.action_chains import ActionChains

  2) ActionChains (browser): generating a simulated user behavior user object

  3) perform () perform the storage behavior

  ActionChains (browser) .move_to_element (ele) .perform () on the mouse to move to a certain element

  Mouse events:

  

  Keyboard events: from seleniu.webdriver.common.keys import Keys

  send_keys()

  

4. A multi-window switch

  browser.current_window_headle # Display the current handle

  browser.window_handles # list all the Handle

  browser.switch_to_window # handle switch

5. The method of waiting for test script

  1) sleep time method used in the sleep mode module:

  2) implicitly_wait () wait time set webdriver

  After 3) WebDriverWait wait timeout condition is met or exit from selenium.webdriver.support.ui import WebDriverWait

6. Alert dialog processing

  

7. The read user data using xlrd

  xlrd data read excel file
  
  installed xlrd pip install xlrd

  xlrd module reads the contents excel:

  1) xl = xlrd.open_workbook ( 'test.xls') # open excel

  2) table = xl.sheets () [0] # acquired by an index sheet

  3) row = table.row_values ​​(0) # obtain the content of the first row

  4) col = table.col_values ​​(0) # acquires content in the first column

  5) table.nrows # rows

  6) table.ncols # number of columns

  7) table.cell (0,0) .value # cell value

8. Use generate test reports excel

  XlsxWriter write excel file

  Installation XlsxWriter pip install XlsxWriter

  XlsxWriter modules:

  1) writing merged cell format cells

  2) support formulas, hyperlinks

  3) Support insert pictures

  4) Support for generating chart

  XlsxWriter example:

  1) Create excel xl = XlsxWriter.workbook ( 'test.xls')

  2)添加sheet  table=xl.add_worksheet('sheet1')

  3) Write the cell table.write_string (0,0, 'first') / ( 'A1', 'first')

  4) set the cell size table.set_column ( 'C: E', 15)

  5) excel off xl.close ()

  

 

 

  

Guess you like

Origin www.cnblogs.com/sunnyxhd/p/11330033.html