1、Xpath

xpath定位当前元素的相邻元素/兄弟元素
2021-05-13 11:23:27

前一位:
../div[@="class"]/preceding-sibling::div[1]
后一位:
../div[@="class"]/following-sibling::div[1]


前N位:
../div[@="class"]/preceding-sibling::div[N]
后N位:
../div[@="class"]/following-sibling::div[N]

 

2、js

 

// 设置日期控件的读写属性

((JavascriptExecutor) driver).executeScript("document.getElementById(\"fromDate\").readOnly=false");
// 直接为日期控件强行赋值
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('fromDate').setAttribute('value','2013-06-21');");
// 富文本编辑框的处理
driver.switchTo().frame("ueditor_0");
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.body.innerHTML='ABCDEFG'");
//js模拟点击
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();",driver.findElement(By.id("su")));
//滚动条操作
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.documentElement.scrollTop=1500");
//元素赋值
document.getElementById('HD_CheckIn').value='zhangsan';
//日期类型元素赋值
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0] .value=‘2016-04-20';",driver.findElement(By*****)));
posted on 2022-05-26 14:44  无知小笨鸟  阅读(29)  评论(0编辑  收藏  举报