• 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)

  • 相关阅读:
    git命令大全
    servlet执行顺序
    github使用教程
    upun使用教程
    jsp标签之<%%>和<%!%>
    spring MVC 详细入门
    jquery之ajax之$.get方法的使用
    jquery之getJSON方法获取中文数据乱码解决方法
    eclipse隐藏菜单栏实现全部酷黑主题
    eclipse快捷键失效的解决办法
  • 原文地址:https://www.cnblogs.com/Appleli/p/11412637.html
Copyright © 2020-2023  润新知