and operation processing chain selenium iframe

and operation processing chain selenium iframe

iframe

iframe is a nested interface in other interfaces, this time selenium can not find the property sub-interface from the main interface, you need to find a sub-interface, then go to the Properties sub-interface

Chain operation (drag)

1.from selenium.webdriver import ActionChains

2. Examples of action of a chain of objects: action = ActionChains (Object Browser)

3.click_and_hold(div)

4.move_by_offset (x, y) to the x, y pixels moved

5.perform () allows immediate action Chain Execution

6.action.release () releasing action target strand

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

Guess you like

Origin www.cnblogs.com/zx125/p/11487521.html
Recommended