以下内容在Python中使用时需要使用execute_script执行js脚本,可以参考:
《WebUI之元素定位(超详细版)》:https://www.jianshu.com/p/2398b8f3d1ef
一、浏览器相关操作
(一)iframe相关
可以查看页面中有几个iframe,length长度即为iframe数量
查看所有iframe内容
window.frames

查看指定索引iframe内容
window.frames[1]

查看iframe的数量
window.length

(二)窗口滚动
绝对滚动:scroll(0,1000)
不管在哪,都会滚动到(0,1000)
相对滚动:scrollBy(0,1000)
往下滚动(0,1000),不停执行,会不停的滚
window.scrollTo(0,document.body.scrollHeight)
window.scrollTo(0,document.body.scrollWidth)
二、元素属性相关操作
(一)获取元素属性
document.getElementsByTagName("a")[0].getAttribute("target")
获取元素的target属性的值,还有另外一种写法:document.getElementsByTagName("a")[0].target
document.getElementById('元素ID').innerHTML=text
(二)设置元素属性:
document.getElementsByTagName().setAttribute(attributename,attributevalue)
document.getElementsByTagName().Attribute=value
或者querySelector().setAttribute(attributename,attributevalue)
querySelector()..Attribute=value
获取元素的标签之间的文本,若后面接=进行赋值操作,那么会设置标签之间的文本。
三、document相关操作
document.title
document.cookie
document.baseURI
document.URI感觉效果一样
其他个人觉得有用的地方:
location.search返回url的search部分