selenium常用操作



对弹窗(alert)的处理

三种弹出框alert(一个按钮),confirm(两个确认,取消),prompt(两个按钮+输入框)。
切换到弹框: switch_to_alert()
新版的selenium用:
browser.switch_to.alert.accept()
browser.switch_to.alert.send_keys('abc')
browser.switch_to.alert.dismiss()
弹框的方法:
1 text获取弹框文本
2 accept()确认
3 dimiss()取消
4 send_keys() prompt弹框输入字符。

css_selector定位详解

selenium之CSS定位汇总
一:单一属性定位
1:type selector
driver.find_element_by_css_selector('input')
2:id 定位
driver.find_element_by_css_selector('#kw')
二:组合属性定位
三:层级定位
参考网址
https://www.cnblogs.com/alex-13/p/12016554.html

ActionChains方法列表

  1.  
    click(on_element=None) ——单击鼠标左键
  2.  
    click_and_hold(on_element=None) ——点击鼠标左键,不松开
  3.  
    context_click(on_element=None) ——点击鼠标右键
  4.  
    double_click(on_element=None) ——双击鼠标左键
  5.  
    drag_and_drop(source, target) ——拖拽到某个元素然后松开
  6.  
    drag_and_drop_by_offset(source, xoffset, yoffset) ——拖拽到某个坐标然后松开
  7.  
    key_down(value, element=None) ——按下某个键盘上的键
  8.  
    key_up(value, element=None) ——松开某个键
  9.  
    move_by_offset(xoffset, yoffset) ——鼠标从当前位置移动到某个坐标
  10.  
    move_to_element(to_element) ——鼠标移动到某个元素
  11.  
    move_to_element_with_offset(to_element, xoffset, yoffset) ——移动到距某个元素(左上角坐标)多少距离的位置
  12.  
    perform() ——执行链中的所有动作
  13.  
    release(on_element=None) ——在某个元素位置松开鼠标左键
  14.  
    send_keys(*keys_to_send) ——发送某个键到当前焦点的元素
  15.  
    send_keys_to_element(element, *keys_to_send) ——发送某个键到指定元素
原文地址:https://www.cnblogs.com/gina11/p/14277255.html