Selenium+python操作id为动态变化的frame(iframe)
先定位到一组frame:ele = dr.find_elements_by_tag_name('iframe')此时获得一组frame
再通过index取需要切进去的frame并取到该frame的id:r = ele[1].get_attribute('id')
接下来就可以直接切换进frame:dr.switch_to.frame(r)
from selenium import webdriver url = 'http://mail.xxxxxx.cn/cgi-bin/frame_html?sid=1t7ez3_A400vGDBp,2&r=306fe5cbf6d3911c1d24bc1f32025c01' dr = webdriver.Chrome() dr.get(url) dr.implicitly_wait(10) dr.find_element_by_id('qquin').clear dr.find_element_by_id('qquin').send_keys('xxxxx') dr.find_element_by_id('pp').clear dr.find_element_by_id('pp').send_keys('xxxxxx') dr.find_element_by_id('btlogin').click() ele = dr.find_elements_by_tag_name('iframe') r = ele[1].get_attribute('id') print r dr.quit()