zoukankan      html  css  js  c++  java
  • selenium处理iframe和动作链

    selenium处理iframe和动作链

    iframe

    iframe就是一个界面里嵌套了其他界面,这个时候selenium是不能从主界面找到子界面的属性,需要先找到子界面,再去找子界面的属性

    动作链(拖动)

    1.from selenium.webdriver import ActionChains

    2.实例化一个动作链对象:action = ActionChains(浏览器对象)

    3.click_and_hold(div)

    4.move_by_offset(x,y)向x,y移动像素

    5.perform()让动作链立刻执行

    6.action.release()释放动作链对象

    from selenium import webdriver
    import time
    from selenium.webdriver import ActionChains
    
    chrome=webdriver.Chrome("chromedriver")
    
    url="https://www.runoob.com/try/try.php?filename=jqueryui-api-droppable"
    
    chrome.get(url)
    
    time.sleep(5)
    
    #找到了子界面
    chrome.switch_to.frame('iframeResult')
    #找到子界面是div
    div=chrome.find_element_by_id("draggable")
    
    #创建动作链
    action=ActionChains(chrome)
    
    #点击长按指定标签
    action.click_and_hold(div)
    
    for i in range(5):
        #向x偏移17,向y偏移2  perform()执行动作链
        time.sleep(0.3)
        action.move_by_offset(17,2).perform()
    
    time.sleep(5)
    #释放动作链
    action.release()
    
    chrome.quit()
    
  • 相关阅读:
    第二章例2-9
    第二章例2-8
    第二章例2-7
    第二章例2-6
    第二章例2-5
    第二章例2-4
    第二章例2-3
    第二章例2-2
    第二章例2-1
    第一章例1-2
  • 原文地址:https://www.cnblogs.com/zx125/p/11487521.html
Copyright © 2011-2022 走看看