Python3+Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)
#!/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)的更多相关文章
- Python3+Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)'''from sel ...
- Python3+Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )
!/usr/bin/env python -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )'''from selenium im ...
- Python3+Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)'''from seleni ...
- Python3+Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记8(单选.复选框.弹窗处理)''' from selenium ...
- Python3+Selenium3+webdriver学习笔记11(cookie处理)
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记11(cookie处理)'''from selenium im ...
- Python3+Selenium3+webdriver学习笔记10(元素属性、页面源码)
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记10(元素属性.页面源码)'''from selenium i ...
- Python3+Selenium3+webdriver学习笔记7(选择多链接的结果、iframe、下拉框)
#!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...
- Python3+Selenium3+webdriver学习笔记6(多窗口切换处理)
#!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...
- Python3+Selenium3+webdriver学习笔记5(模拟常用键盘和鼠标事件)
#!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...
随机推荐
- SQLServer 微软团队开源项目 (web 版?)
http://www.codeplex.com/site/users/view/SQLTeamAdmin
- 26.OpenIdConnect获取用户信息的两种方式
openId在OAuth基础之上,在下面这红框内拿到Authorization Code之后还可以返回IdToken. IdToken和AccessToken一起返回.IdToken就会包括了用户的信 ...
- eclipse里的Maven插件安装
插件安装 打开Eclipse的Help->Install New Software,如下图所示: 2. 选择“Add..”按钮,又会弹出如下对话框: 这个对话框就是用于添加一个插件地址的.在“N ...
- Linux下的eclipse的安装
其实在linux里配好java环境后,就已经好了. 从官网下一个eclipse,解压后,就可以直接执行eclipse了,实在是不知道什么是安装. 其实在配置java时,也是一样. 可见在linux下, ...
- 洛谷P2016 战略游戏
P2016 战略游戏 题目描述 Bob喜欢玩电脑游戏,特别是战略游戏.但是他经常无法找到快速玩过游戏的办法.现在他有个问题. 他要建立一个古城堡,城堡中的路形成一棵树.他要在这棵树的结点上放置最少数目 ...
- NetCore + Mysql + EF:No coercion operator is defined between types 'System.Int16' and 'System.Boolean',
总结三种解决办法: 1.Mysql升级到7 2.Nuget安装Pomelo.EntityFrameworkCore.MySql 2.2.0替代MySql.Data.EntityFrameworkCor ...
- MySql提示:The server quit without updating PID file(…)失败之解决办法(来源网络仅供参考)
1.可能是/usr/local/mysql/data/rekfan.pid文件没有写的权限 解决方法 :给予权限,执行 “chown -R mysql:mysql /var/data” “chmod ...
- 5.用通配符进行过滤 ---SQL
一.LIKE操作符 通配符(wildcard) 用来匹配值的一部分的特殊字符.搜索模式(search pattern)由字面值.通配符或两者组合构成的搜索条件.通配符本身实际上是SQL的WHERE子句 ...
- Sicily 1027. MJ, Nowhere to Hide
//就是一个简单的字符串配对~~用map来解决很easy #include <iostream> #include <map> #include <string> ...
- A Simple Math Problem (矩阵快速幂)
Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 f(x) = a0 ...