2019-01-18python selenium 获取frame中的元素

如何在selenium中使用

例:网页中有源码:

获取步骤:

(1)假如我们想要获取id=”haha”的div标签,直接通过driver.find_element_by_id(‘haha’)就会提示“元素不存在“的错误。

(2)这时候我们需要使用

driver.switch_to_frame(driver.find_element_by_id“(“topmenuFrame”)),即先进入id为topmenuFrame的frame,然后再执行driver.find_element_by_id(“haha”),就能正确获得该元素了。

(3)返回到原来的iframe

需要注意的是,切换到这个frame之后,只能访问当前frame的内容,如果想要回到默认的内容范围,相当于默认的frame,还需要使用driver.switch_to_default_content()。

(4)注意事项

页面中有多个frame时,要注意frame之间的切换。

---------------------

作者:xudailong_blog

来源:CSDN

原文:https://blog.csdn.net/xudailong_blog/article/details/80034906

版权声明:本文为博主原创文章,转载请附上博文链接!

你可能感兴趣的:(2019-01-18python selenium 获取frame中的元素)