python, selenium automation common keywords

A: Positioning eight methods

  E.g:

  II: Common methods webdriver

  1. Open the browser-related :( browser to import webdriver module)

  (1) set_window_size (480,800) to adjust the width size of the browser high

  (2) maximize_window () to maximize the browser

  (3) back () back

  (4) forward () forward

  (5) refresh () Refresh

  (6) close () Close the current browser

  (7) quit () Close all browser

  (8) js = "window.scrollto (300,200)" # 300 represents the left margin, the margin 200 denotes

  (9) browser properties (handle)

  Handle current_window_handle current page

  window_handles handle all current

  (10) switch_to_window () switching windows (typically by handles handover)

  2. Text button operations related to:

  (1) send_keys () input text

  (2) clear () Clear text

  (3) click () click the button

  (4) submit () Enter the similar input text

  (5) size Returns the size of the element

  (6) text get the text

  (7) get_attribute (type) Gets the property value

  3. Mouse-related

  (1) context_click () Right-click

  (2) double_click () Double-

  (3) drag_and_drop () drag

  (4) move_to_element () Hover

  (5) perform () execution

  4. Wait related

  (1) implicitly_wait () implicitly wait, good flexibility

  (2) time.sleep () wait

  5. checkbox related

  6. A drop-down box process

  (1) select the positioning module

  from selenium.webdriver.support.select import Select

  # Import select module

  Select offers three selection methods:

  select_by_index(index) ——通过选项的顺序,第一个为 0

  select_by_value(value) ——通过value属性

  select_by_visible_text(text) ——通过选项可见文本

  Select提供了四种方法取消选择:(只能取消选择多选选项)

  deselect_by_index(index)

  deselect_by_value(value)

  deselect_by_visible_text(text)

  deselect_all()

  (2)二次定位(基本思路,先定位 select 框,再定位 select 里的选项)

  7.iframe相关

  (1)switch_to.frame()选择一个frame---只能用id或name定位frame

  (2)假如iframe没有可定位的id或name那么可以通过xpath先定位到iframe,再将对象传给switch_to.frame():如下

  iframe_xpath=driver.find_element_by_xpath('//*[@class="if"]')

  driver.switch_to.frame(iframe_xpath)

  .......

  (3)switch_to.default_content()取消选择一个frame(跳回最外层的页面)

  switch_to.parent _content()取消选择一个frame(跳出当前frame)

  8.弹窗相关

  (1)switch_to_ #确定

  (2)switch_to_ #取消

  (3)browser.switch_to_.text #获取弹框信息

  9.调用selenium下的by库里的By模块

  (1)先导库:from selenium.webdriver.common.by import By

  (2) repositioning elements: driver.find_element (By.ID, 'kw')

  10. The data precision adjustment of decimal places

 

 

Guess you like

Origin www.cnblogs.com/jiachangwei/p/12293556.html