zoukankan      html  css  js  c++  java
  • python3-selenium-UI自动化入门二

    ###

    接上一篇

    ###

    一、消息窗

    #切换到页面的消息窗

    a = driver.switch_to_alert

    a.text#消息窗文本

    a.accept()#相当于点击“确定”

    a.dismiss()#相当于点击“取消”

    二、切换页面框架

    例如

    baidu = driver.find_element_by_css_selector('iframe#id')#先定位要切换的框架

    driver.switch_to.frame(baidu)#切换

    #切换回上一级框架

    driver.switch_to.parent_frame()

    #切换到最外层框架

    driver.switch_to.default_content()

    三、切换浏览器窗口

    #获得打开的所有的窗口句柄

    window = driver.window_handles

    #切换到当前最新打开的窗口

    driver.switch_to.window(window[-1])

    四、鼠标操作

    from selenium.webdriver.common.action_chains import ActionChains

    1、悬停

    #先定义一个实例

    action = ActionChains(driver)

    #添加一个事件,el为定位好的元素

    action.move_to_element(el)

    #执行添加好的事件

    action,perform()

    2、左键按住不放

    action = ActionChains(driver)

    #el元素按住3s,然后释放

    action.click_and_hold(el).press(3).release().perform()

    3、右键点击

    action = ActionChains(driver)

    #action.context_click(el).perform()

    4、拖拽

    action = ActionChains(driver)

    #把元素el拖到那个坐标上

    action.drag_and_drop_by_offset(el,500,600).perform()

    四、js点击元素

    driver.execute_script("arguments[0].click();",el)

  • 相关阅读:
    CentOS下编译搭建LAMP环境
    RabbitMQ消息队列总结
    利用exif.js解决ios手机上传竖拍照片旋转90度问题
    服务器同一个tomcat部署2两个相同的项目
    php curl 转为 x-www-form-urlencoded 方式的坑
    Linux后台运行Java的jar包
    环境隔离与属性替换
    安装与使用adb
    HTTP状态码
    微信小程序官方文档
  • 原文地址:https://www.cnblogs.com/Appleli/p/11412637.html
Copyright © 2011-2022 走看看