zoukankan      html  css  js  c++  java
  • selenium---操作iframe中的滚动条

    前言

      在做web自动化时候,可能会需要用到滑动滚动条的操作,前面安静介绍了通过JS操作一般的滚动条,那么如果滚动条在iframe中呢?这个时候应该怎么操作呢?

     编写iframe实例

    安静这里写了一个将百度页面代码放入到单独的一个页面中,然后通过另一个html通过iframe的方式进行调用百度的html。

    再编写一个html的方式用来调用baidu.html。其中src后面的路径表示我们的调用的路径。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>滑动iframe</title>
    </head>
    <body>
    <iframe src="file:///E:/web/baidu.html" frameborder="no" id="anjing" width="80%" height="500">
    </iframe>
    </body>
    </html>

    通过打开页面是这样的

    代码实例

    需要用的内容都用到了,接下来就是通过我们实战演习了。我们在前面介绍过如何跳入到iframe中,其实这样也是一样的,我们先跳入到iframe中,然后在通过JS的方式执行滚动条。

    from selenium import webdriver
    import time
    driver = webdriver.Chrome()
    driver.get(r'E:web123.html')
    time.sleep(3)
    driver.switch_to.frame('anjing')
    js = 'window.scrollTo(0, 1000)'
    driver.execute_script(js)

    通过执行后发现我们iframe中的滚动条已经滑动了

  • 相关阅读:
    今日总结
    今日总结
    每日总结
    每日总结
    小程序之navigator跳转方式
    vue面试题(上)
    ES6 中的 set 用法
    维信小程序 如何 实现下拉刷新?
    微信小程序的相关文件类型有哪些??
    vue中v-if与v-show的区别以及使用场景
  • 原文地址:https://www.cnblogs.com/qican/p/15386554.html
Copyright © 2011-2022 走看看