#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)
'''
from selenium import webdriver import time,os # about:addons 火狐浏览器安装组件,访问的地址 # <input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
#id
keys="selenium自动化"
delay=3
# url="https://www.cnblogs.com/nicetime"
# url="https://www.12306.cn/index/"
url="file:///D:/ideaSpace/autoProject/python_autotest/nicetime/webdriver/js12.html"
driver=webdriver.Firefox() driver.get(url) #回到底部
js2="var q=document.documentElement.scrollTop=10000"
driver.execute_script(js2) js22="window.scrollTo(0,document.body.scrollHeight)"
driver.execute_script(js22) time.sleep(delay) #回到顶部
js1="var q=document.documentElement.scrollTop=0" # chrome浏览器
# js11="var q=document.body.scrollTop=0"
driver.execute_script(js1) js12="window.scrollTo(0,0)"
driver.execute_script(js12) # #左右滚动
js3="window.scrollTo(100,400)"
driver.execute_script(js3) # #聚焦元素 find_element_by系列
target=driver.find_element_by_id("blog_nav_sitehome")
driver.execute_script("arguments[0].scrollIntoView();",target) # 兼容浏览器
def scroll_Top():
if driver.name=="chrome":
js="var q=document.body.scrollTop=0"
else:
js="var q=document.documentElement.scrollTop=0"
return driver.execute_script(js) def scroll_down():
if driver.name=="chrome":
js="var q=document.body.scrollTop=10000"
else:
js="var q=document.documentElement.scrollTop=10000"
return driver.execute_script(js) #滚动高度 滚动宽度
# document.body.scrollHeight
# document.body.scrollWidth #日历处理-输入指定的日期
# <input type="text" class="input" value="2018-07-21" id="train_date" readonly="">
#去掉只读属性
js1='document.getElementById("train_date").removeAttribute("readonly");'
driver.execute_script(js1) time.sleep(delay) #输入日期
date="2018-12-04"
js2='document.getElementById("train_date").value="%s"'%date
driver.execute_script(js2) time.sleep(delay) #清空文本框后输入值
driver.find_element_by_id("train_date").clear()
driver.find_element_by_id("train_date").send_keys(date) time.sleep(delay) #内嵌div
# 纵向底部 顶部
js3='document.getElementById("ideaic").scrollTop=10000'
driver.execute_script(js3)
time.sleep(delay) js4='document.getElementById("ideaic").scrollTop=0'
driver.execute_script(js4)
time.sleep(delay) # 横向右侧 左侧
js5='document.getElementById("ideaic").scrollLeft=10000'
driver.execute_script(js5)
time.sleep(delay) js6='document.getElementById("ideaic").scrollLeft=0'
driver.execute_script(js6)
time.sleep(delay) #用class定位
js7='document.getElementsByClassName("scroll")[0].scrollTop=10000'
driver.execute_script(js7)
time.sleep(delay) js8='document.getElementsByClassName("scroll")[0].scrollLeft=10000'
driver.execute_script(js8)
time.sleep(delay) driver.quit()

Python3+Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)的更多相关文章

  1. Python3+Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)'''from sel ...

  2. Python3+Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )

    !/usr/bin/env python -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )'''from selenium im ...

  3. Python3+Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)'''from seleni ...

  4. Python3+Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记8(单选.复选框.弹窗处理)''' from selenium ...

  5. Python3+Selenium3+webdriver学习笔记11(cookie处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记11(cookie处理)'''from selenium im ...

  6. Python3+Selenium3+webdriver学习笔记10(元素属性、页面源码)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记10(元素属性.页面源码)'''from selenium i ...

  7. Python3+Selenium3+webdriver学习笔记7(选择多链接的结果、iframe、下拉框)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...

  8. Python3+Selenium3+webdriver学习笔记6(多窗口切换处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...

  9. Python3+Selenium3+webdriver学习笔记5(模拟常用键盘和鼠标事件)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...

随机推荐

  1. VS2008 查找失效怎么办

    按Ctrl+F没有反应?   visual studio 里 查找替换 显示不出来;   还能用 让他查找个不存在的文本还会弹出找不到的提示; 就是看不到 查找替换的操作框了;   问题解决方法:   ...

  2. java——static声明方法注意事项

    在使用 static 类型声明的方法时需要注意的是:如果在类中声明了一 static类型的属性,则此属性既可以在非 static 类型的方法中使用,也可以在 static类型的方法中使用.但用 sta ...

  3. day12Session案例 JSP

    2 Session案例 用户登录场景 package gz.itcast; import java.io.IOException; import java.io.PrintWriter; import ...

  4. 2、CDH组件安装

    一.zookeeper 1.安装 继续->完成: 二.HDFS 1.安装 继续->完成: 三.yarn.hive 1.安装yarn 继续->完成: 2.安装hive 继续->完 ...

  5. Spring Boot实现学生信息增删改查

    上一篇博客写了如何初始化一个简单的Spring Boot项目,这次详细记录一下如何连接数据库并实现增删改查基本操作. 我使用的是MySQL 5.5+Navicat,MySQL量级比较轻,当然微软的SQ ...

  6. charles关于手机APP抓包

    这里相比其他抓包软件来说要简单的多了,具体步骤如下: 1 使手机和电脑在一个局域网内,不一定非要是一个ip段,只要是同一个漏油器下就可以了,比如电脑连接的有线网ip为192.168.16.12,然后手 ...

  7. 【转】 mybatis如何在控制台打印执行的sql语句

    <strong>######################################################################### #Root Logger ...

  8. 获得用户IP、城市、国家等信息的api接口

    1 这个信息比较多 https://api.ipdata.co/?api-key=test <script> $.get("https://api.ipdata.co?api-k ...

  9. Weekly Contest 112

    945. Minimum Increment to Make Array Unique Given an array of integers A, a move consists of choosin ...

  10. js混杂笔记

    1.判断对象为空的方法 1)Object.keys({}).length === 0 // true 2)Object.getOwnPropertyNames({}).length === 0 // ...