1. 滚动窗口:
 //将滚动条滚到适合的位置  , 方法一
public static void setScroll(WebDriver driver,int height){
try { // String setscroll = "document.documentElement.scrollTop=" + height;
String setscroll = "document.body.scrollTop=" + height;
JavascriptExecutor jse=(JavascriptExecutor) driver;
jse.executeScript(setscroll); } catch (Exception e) {
System.out.println("Fail to set the scroll.");
}
}
//将滚动条滚到适合的位置 , 方法二
public static void setScroll2(WebDriver driver,By by){
try {
WebElement page2 = driver.findElement(by);
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("arguments[0].scrollIntoView()", page2); } catch (Exception e1) {
System.out.println("Fail to set the scroll.");
}
}
//将滚动条滚到适合的位置 , 方法三
public static void scrollToElement(WebDriver driver,By by) {
WebElement e = driver.findElement(by);
logger.info("scroll view element");
JavascriptExecutor js = (JavascriptExecutor) driver;
// roll down and keep the element to the center of browser
js.executeScript("arguments[0].scrollIntoViewIfNeeded(true);", e);
} //滚动到目标元素的纵坐标位置(Link),点击 public void scrollAndClick(WebDriver driver,By by)
{
WebElement element = driver.findElement(by);
int elementPosition = element.getLocation().getY();
String js = String.format("window.scroll(0, %s)", elementPosition);
((JavascriptExecutor)driver).executeScript(js);
element.click();
}

2. 判断web链接返回状态是否为2开头

//        封装判断web链接返回状态是否为2开头的
public static void ReadUrl(String surl){
try {
URL url = new URL(surl);
URLConnection rulConnection = url.openConnection();
HttpURLConnection httpUrlConnection = (HttpURLConnection) rulConnection;
httpUrlConnection.setConnectTimeout(300000);
httpUrlConnection.setReadTimeout(300000);
httpUrlConnection.connect();
String code = new Integer(httpUrlConnection.getResponseCode()).toString();
String message = httpUrlConnection.getResponseMessage();
System.out.println("getResponseCode code ="+ code);
System.out.println("getResponseMessage message ="+ message);
if(!code.startsWith("2")){
throw new Exception("ResponseCode is not begin with 2,code="+code);
}
// 打印链接返回状态码
// System.out.println(getDateTime()+"连接"+surl+"正常");
}catch(Exception ex){
System.out.println(ex.getMessage());
}
}

最新文章

  1. c#批量插入数据库Demo
  2. [Scala] Scala基础知识
  3. category用法
  4. mysql 5.6.34 二进制
  5. jquery easyui的treegrid的控制
  6. jQuery 操作复选框(checkbox) attr checked不起作用
  7. 防止apache下面直接输入目录访问文件
  8. 关于hbase的read操作的深入研究 region到storefile过程
  9. [SCOI2009]游戏
  10. 淘宝开源Web服务器Tengine安装教程
  11. nyoj 757 期末考试【优先队列+贪心】
  12. Linux学习笔记5——虚拟内存
  13. UVALive - 3263 That Nice Euler Circuit (几何)
  14. cordova.js的坑
  15. 通用的Android控件抖动效果实现
  16. rpm和yum软件管理(week2_day5)--技术流ken
  17. 编译器处理警告、错误 #pragma GCC diagnostic ignored "-Wunused"
  18. javascript判断两个对象属性以及值是否相等
  19. linux下搭建我的世界spongeforge 服务器 (海绵端)
  20. Server runtime

热门文章

  1. git记住提交密码的技巧
  2. C Primer Plus note1
  3. 使用SSH连接LINUX的命令
  4. nodejs繁琐地自建路由
  5. base64的编码解码的一些坑
  6. Android 高速录像(2)
  7. Js 对Dom的操作
  8. ado.net c#基本的增加,修改,删除,查询
  9. idea配置maven后提示 commond not found
  10. Element和vue框架报错提示