元素在iframe中。在html当中,内嵌了另一个html (iframe)
分辨元素是否在iframe当中
在代码当中,从当前的html切换到iframe当中的html,然后在元素定位
切换方式:driver.switch_to.frame(iframe的标识)
如下图,有三种切换iframe的方式:
driver.switch_to.frame("private-msgs-iframe") # name属性
driver.switch_to.frame(1) #下表
driver.switch_to.frame(driver.find_element(By.XPATH,'//[@iframe(@id="private-msgs-iframe"]')) # 元素路径
sleep(1) # 切换iframe后找不到元素时,可以加个强制等待时间
主html 内嵌 iframe(html) 再嵌 iframe(html) 再嵌。。。。
从主html切换到第一层iframe:driver.switch_to.frame(iframe的标识)
第一层iframe切换到第二层iframe:driver.switch_to.frame(iframe的标识)
...
返回上一层iframe:driver.switch_to.parent_frame()
返回主html:driver.switch_to.default_content()