• selenium--鼠标键盘事件


    #####################################################
    ## 键盘&鼠标事件
    #####################################################
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.support.ui import Select
    
    ## 键盘事件
    b = webdriver.Chrome()
    b.implicitly_wait(1)
    b.get('http://www.baidu.com')
    b.maximize_window()
    
    ipt_keyword = b.find_element_by_id('kw')
    
    ipt_keyword.send_keys('abcdegf')
    
    for i in range(6):
        ipt_keyword.send_keys(Keys.BACKSPACE)
        sleep(1)
    
    # 最low的方法
    # ipt_keyword.clear()
    # ipt_keyword.send_keys('a')
    
    sleep(3)
    b.quit()
    
    
    
    ## 鼠标悬停
    
    b = webdriver.Chrome()
    b.implicitly_wait(1)
    b.get('http://www.baidu.com')
    b.maximize_window()
    
    lnk_more = b.find_element_by_link_text('更多产品')
    
    ActionChains(b).move_to_element(lnk_more).perform()
    
    lnk_wenku = b.find_element_by_link_text("文库")
    lnk_wenku.click()
    
    sleep(3)
    b.quit()
    
    
    
    ## 鼠标拖拽
    
    b = webdriver.Chrome()
    b.implicitly_wait(1)
    b.get('file:///E:/ZM20190316/2.Selenium/TestDemo/drag&DropDemo/Drag&DropDemo.html')
    b.maximize_window()
    
    ele1 = b.find_element_by_id('dragger')
    
    eles = b.find_elements_by_class_name("item")
    
    for e in eles:
        ActionChains(b).drag_and_drop(ele1, e).perform()
        sleep(1)
    
    # for i in range(len(eles)):
    #     ActionChains(b).drag_and_drop(ele1, eles[i]).perform()
    #     sleep(1)
    
    sleep(3)
    b.quit()
  • 相关阅读:
    15.Mysql之undo 日志浅谈02
    14.Mysql之redo log -checkpoint浅谈01
    13. Mysql之二进制日志(binlog)
    [C]使用argv的5种方法
    [Python]sys.stdin.readline(), sys.stdout.write(), sys.stdin.write()
    temporadas[i][2]三种等价形式
    time.h中time(NULL),stdlib.h中srand(), rand()
    strstr函数的使用
    [C]toupper, tolower
    [Python]List Comprehension
  • 原文地址:https://www.cnblogs.com/chen-huan/p/11011320.html
Copyright © 2020-2023  润新知