zoukankan      html  css  js  c++  java
  • Selenium 实战到吹牛系列:八

    Selenium 实战到吹牛系列


    PS:滚动屏幕

    例子

    代码:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Date    : 2019-07-15 16:12:33
    # @Author  : BenLam
    # @Link    : https://www.cnblogs.com/BenLam/
    
    from selenium import webdriver
    driver=webdriver.Firefox()
    driver.get(r'test.html')
    
    # 向下移动 500 个像素点,代表x, y轴
    driver.execute_script("window.scrollBy(0,500)"# 同上,下降 1000 个像素点
    # PS:不同的浏览器,可能或存在兼容问题
    driver.execute_script("window.scrollBy(0,1000)")
    
    driver.quit()
    

    例子_B

    PS: 滚动屏幕并定位元素, 这里我们打开博客园,定位到“统计信息”栏

    代码:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Date    : 2019-07-15 16:12:33
    # @Author  : BenLam
    # @Link    : https://www.cnblogs.com/BenLam/
    
    from selenium import webdriver
    driver=webdriver.Firefox()
    driver.get(r'https://www.cnblogs.com/')
    
    # 先找元素
    a = driver.find_element_by_xpath(r'//*[@id="side_nav"]/div[7]/h4')
    
    # 通过 js 方式找滚动到元素所在地方
    # 打印 text 显示为 “'统计信息'”
    text = driver.execute_script("return arguments[0].scrollIntoView();", a)
    
    driver.quit()
    
  • 相关阅读:
    Docker 部署项目
    Python+Pywinauto+Lackey 实现PC端.exe 自动化测试
    03_Fiddler 导出jmx文件
    02_Postman 中文汉化版
    07_Linux系统(Centos)安装tomcat和部署Web项目
    05_oracel题集
    02_appium基本使用
    01_appium的安装
    02_Monkey使用
    01_Monkey安装
  • 原文地址:https://www.cnblogs.com/BenLam/p/11188714.html
Copyright © 2011-2022 走看看