以下內(nèi)容在Python中使用時需要使用execute_script執(zhí)行js腳本坷澡,可以參考:
《WebUI之元素定位(超詳細版)》:http://www.reibang.com/p/2398b8f3d1ef
一氓奈、瀏覽器相關操作
(一)iframe相關
可以查看頁面中有幾個iframe崖疤,length長度即為iframe數(shù)量
查看所有iframe內(nèi)容
window.frames
查看指定索引iframe內(nèi)容
window.frames[1]
查看iframe的數(shù)量
window.length
(二)窗口滾動
絕對滾動:scroll(0,1000)
不管在哪,都會滾動到(0,1000)
相對滾動:scrollBy(0,1000)
往下滾動(0,1000)西设,不停執(zhí)行,會不停的滾
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部分