美文网首页
2019-01-18python selenium 获取fram

2019-01-18python selenium 获取fram

作者: 小草_f57c | 来源:发表于2019-01-18 17:23 被阅读0次

如何在selenium中使用

例:网页中有源码:

<iframe id="topmenuFrame" width="100%" scrolling="no" height="100%" src="topmenu.aspx?>

<div id="haha">text</div>

</iframe>

获取步骤:

(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 获取fram

      本文链接:https://www.haomeiwen.com/subject/liandqtx.html