iframe切换

iframe(locator有三种情况,可以是:定位表达式(driver.find_element_by_xpath()),frame的名称,下标index)

driver.switch_to.frame(locator)   #切换iframe

driver.switch_to.parent_frame()  #这个方法适用于嵌套iframe,当你有父级iframe,子级iframe,那么你当前位置是子级iframe,那么你想切换回父级iframe,那么就需要使用 switch_to.parent_frame() ,退回到父级iframe

driver.switch_to.default_content()  #退回最外层html

等待方法可以自动切换iframe

WebDriverWait(driver,20,1).until(EC.frame_to_be_available_and_switch_to_it(ele))

原文地址:https://www.cnblogs.com/hao2018/p/9641948.html