selenium處理iframe
如果定位的標籤在iframe中,必須使用swith_to.frame(id)
動作鏈: from selenium.webdriver import ActionChains
實例會動作鏈
執行相關動作
釋放動作鏈
from selenium import webdriver
from time imprt sleep
bro=webdriver.Chrome(executable_path='./chromedriver')
bro.get('https:// ?')
bro.find_element_by_id('draggable')#在iframe中是定位不到的
如果定位的標籤存在於iframe標籤之中的則必須通過如下操作再進行標籤定位
bro.switch_to.frame('iframeResult')#切換瀏覽器作用域
bro.find_element_by_id('draggable')
用到動作鏈
from selenium.webdriver import ActionChains
action=ActionChains(bro)
action.click_and_hold(div)#點擊長按
for i in rang(5)
action.move_by_offset(17,0).perform() #perform()讓動作立即執行
action.release()釋放動作鏈
bro.quit()
簡單案例登錄QQ
bro.get("https://qzone.qq.com/')
bro.switch_to.frame('login_from')
a_tag=bro.find_element_by_id('switch_plogin')
a_tag.click()
username_tag=bro.find_elemetn_by_id('u')
username_tag.send_keys()
btn=bro.find_element_by_id('login_button")
btn.click()