zoukankan      html  css  js  c++  java
  • web自动化测试---测试中其他一些常用操作

      一些其他常用操作如下:

    1、最大化浏览器窗口

    driver.maximize_window()
    

    2、后退

    driver.back()
    

    3、前进

    driver.forward()
    

    4、刷新操作

    driver.refresh()
    

    5、告警窗口

    driver.switch_to.alert.accept()
    #打印告警信息
    driver.switch_to.alert.text

    6、移动鼠标到元素上(不进行任何操作)

    from selenium.webdriver.common.action_chains import ActionChains
    import time
    
    driver=webdriver.Firefox()
    driver.get("http://www.baidu.com")
    element=driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/a[8]')
    ActionChains(driver).move_to_element(element).perform()
    time.sleep(3)
    driver.quit()
    

    7、鼠标双击操作

    ActionChains(driver).double_click(element).perform()

    8、鼠标右击操作

    ActionChains(driver).context_click(element).perform()

    9、左键点击元素但不放开

    ActionChains(driver).click_and_hold(element).perform()
    

    10、把元素element1拖放到element2元素上

    ActionChains(driver).drag_and_drop(element1,element2).perform()

    11、把鼠标向右移动2个像素再向上移动3个像素

    ActionChains(driver).move_by_offset(2,3).perform()

     如果只是向右移动,那把3改成0即可

    12、重置句柄

    ActionChains(driver).reset_actions()

    13、下拉框选择

    from selenium.webdriver.support.ui import Select
    
    #根据value选择
    Select(element).select_by_value('1')
    #根据index选择
    Select(element).select_by_index(1)
    
    关于本篇内容如有转载请注明出处;技术内容的探讨、纠错,请发邮件到70907583@qq.com
  • 相关阅读:
    Python自学笔记(12day)
    Python自学笔记(11day)
    Python自学笔记(10day)
    Python自学笔记(9day)
    Python自学笔记(8day)
    form标签的使用
    form标签的使用法
    img标签的使用方法
    <a></a>标签的使用
    html的标签
  • 原文地址:https://www.cnblogs.com/watertaro/p/9053138.html
Copyright © 2011-2022 走看看