Webdriver控制翻页控件,并实现向前向后翻页功能,附上代码,仅供参考,其他类似日期控件的功能可以自己封装
新增输入与选择页面的html源码:
<div style="margin-top:-60px;" class="modal-content" id="modalContent">
<div class="modal-head">
<a title="关闭" style="margin-right:20px;" data-dismiss="modal" class="close" href="javascript:void(0);">×</a>
<h6> </h6>
</div>
<div id="contentBody" class="modal-body">
<!-- 查询条件 -->
<form id="newForm" method="post" action="">
<input type="hidden" id="addTagHidden">
<input type="hidden" name="tagCode" id="tagCodeHidden">
<table style="width:100%;" id="tb_gbcBiddingCatalogueNew" class="table table-bordered">
<colgroup>
<col width="20%">
<col width="30%">
<col width="20%">
<col width="30%">
</colgroup>
<tbody>
<tr>
<td class="text-right"><span style="color:red">*</span>药易编码:</td>
<td><input type="text" required="required" validatetype="valiSymbol" name="code2" id="newCode2" class="form-control"></td>
<td class="text-right"><span style="color:red">*</span>统编代码:</td>
<td><input type="text" required="required" readonly="readonly" validatetype="valiSymbol" name="code" id="newCode" class="form-control"></td>
</tr>
<tr>
<td class="text-right"><span style="color:red">*</span>药品通用名:</td>
<td><input type="text" required="required" readonly="readonly" validatetype="valiSymbol" name="genericName" id="newGenericName" class="form-control"></td>
<td class="text-right"><span style="color:red">*</span>通用名拼音码:</td>
<td><input type="text" required="required" readonly="readonly" validatetype="valiSymbol" name="pinyin" id="newPinyin" class="form-control"></td>
</tr>
<tr>
<td class="text-right">商品名:</td>
<td><input type="text" readonly="readonly" validatetype="valiSymbol" name="brand" id="newBrand" class="form-control"></td>
<td class="text-right">商品名拼音码:</td>
<td><input type="text" readonly="readonly" validatetype="valiSymbol" name="brandPinyin" id="newBrandPinyin" class="form-control"></td>
</tr>
<tr>
<td class="text-right"><span style="color:red">*</span>剂型:</td>
<td><input type="text" required="required" readonly="readonly" validatetype="valiSymbol" name="dosageForm" id="newDosageForm" class="form-control"></td>
<td class="text-right"><span style="color:red">*</span>制剂规格:</td>
<td><input type="text" required="required" readonly="readonly" validatetype="valiSymbolModel" name="dosageModel" id="newDosageModel" class="form-control"></td>
</tr>
<tr>
<td class="text-right"><span style="color:red">*</span>包装规格:</td>
<td><input type="text" required="required" readonly="readonly" validatetype="valiSymbolModel" id="newPackModel" name="packModel" class="form-control"></td>
<td class="text-right"><span style="color:red">*</span>包装单位:</td>
<td><input type="text" required="required" readonly="readonly" validatetype="valiSymbol" id="newPackUnit" name="packUnit" class="form-control"></td>
</tr>
<tr>
<td class="text-right"><span style="color:red">*</span>生产企业:</td>
<td><input type="text" required="required" readonly="readonly" validatetype="valiPosiFloat" name="producerName" id="newProducerName" class="form-control"></td>
<td class="text-right">原统编代码:</td>
<td><input type="text" placeholder="新码替换旧码时请填写" validatetype="valiSymbol" name="oldTbdm" id="newOldTbdm" class="form-control"></td>
</tr>
<tr>
<td class="text-right"><span style="color:red">*</span>价格类型:</td>
<td>
<!-- 价格类型(1最高零售价;2无最高零售价;3唯一中标价4浮动中标价5挂网采购价6低价药7无采购价规则) -->
<select class="form-control" name="priceType" id="newPriceType">
<option value="1">最高零售价</option>
<option value="2">无最高零售价</option>
<option value="3">唯一中标价</option>
<option value="4">浮动中标价</option>
<option value="5">挂网采购价</option>
<option value="6">低价药</option>
<option value="7">无采购价规则</option>
</select>
</td>
<td class="text-right">价格:</td>
<td><input type="text" validatetype="valiPosiFloat" id="newPrice" name="price" class="form-control"></td>
</tr>
<tr>
<td class="text-right"><span style="color:red">*</span>生效日期:</td>
<td>
<div style="width: 100%;" class="input-medium date datetime">
<input type="text" required="required" readonly="" class="form-control datetime_from" size="10" id="newEffectiveTime" name="effectiveTime">
<span class="add-on"><i class="icon-remove"></i></span><span class="add-on"><i class="icon-th"></i></span>
</div>
</td>
<td class="text-right"><span style="color:red">*</span>失效日期:</td>
<td>
<div style="width: 100%;" class="input-medium date datetime">
<input type="text" required="required" readonly="" class="form-control datetime_to" size="10" id="newExpiryTime" name="expiryTime">
<span class="add-on"><i class="icon-remove"></i></span><span class="add-on"><i class="icon-th"></i></span>
</div>
</td>
</tr>
<tr>
<td class="text-right"><span style="color:red">*</span>新增依据:</td>
<td colspan="3"><input type="text" validatetype="valiSymbol" required="required" id="newRemarks" name="remarks" class="form-control"></td>
</tr>
<!-- 添加标签功能暂时屏蔽掉 -->
<!-- <tr> -->
<!-- <td colspan="4"><a href="javascript:void(0);" class="btnAddTags" >添加标签</a></td> -->
<!-- </tr> -->
<tr style="display:none" id="tagsTR">
<td id="tagsTD" colspan="4">
</td></tr>
</tbody>
</table>
<div style="width:100%;text-align:center;padding:20 0 0 0;">
<input type="button" style="width:120px;" id="btnNewSave" value="提交" class="btn btn-primary btn-sm">
<input type="button" style="width:120px;margin-left:30px;" id="btnNewCancel" value="取消" class="btn btn-primary btn-sm">
</div>
</form>
<!-- 弹出窗口 -->
<div id="showModalNew" role="dialog" tabindex="-1" class="modal fade">
<div class="modal-dialog modal-lg">
<div style="width:500px" class="modal-content" id="modalContent">
<div class="modal-head">
<h6> </h6>
</div>
<div id="contentBodyNew" class="modal-body"></div>
</div>
</div>
</div>
</div>
</div>
对新增输入与选择页面的所有功能进行封装:
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
public class EntryGbcData {
WebElement newCode2;
WebElement newOldTbdm;
WebElement newPriceType;
WebElement newPrice;
WebElement newEffectiveTime;
WebElement newExpiryTime;
WebElement newRemarks;
WebElement btnNewSave;
WebElement btnNewCancel;
List<WebElement> parentDateWidget;
public void findelement(WebDriver driver) {
newCode2 = driver.findElement(By.id("newCode2"));
newOldTbdm = driver.findElement(By.id("newOldTbdm"));
newPriceType = driver.findElement(By.id("newPriceType"));
newPrice = driver.findElement(By.id("newPrice"));
newEffectiveTime = driver
.findElement(By.xpath("/html/body/div[6]/div/div/div[2]/form/table/tbody/tr[8]/td[2]/div/span[2]/i"));
newExpiryTime = driver
.findElement(By.xpath("/html/body/div[6]/div/div/div[2]/form/table/tbody/tr[8]/td[4]/div/span[2]/i"));
parentDateWidget = driver
.findElements(By.cssSelector(".datetimepicker.datetimepicker-dropdown-bottom-right.dropdown-menu"));
newRemarks = driver.findElement(By.id("newRemarks"));
btnNewSave = driver.findElement(By.id("btnNewSave"));
btnNewCancel = driver.findElement(By.id("btnNewCancel"));
}
/**
* 提供中标目录的输入和选择功能
*
* @param driver
* @param yybm
* 药易编码
* @param priceType
* 价格类型
* @param price
* 价格
* @param effectiveTime
* 生效日期
* @param expiryTime
* 失效日期
* @param xzyj
* 新增依据
* @throws Exception
*/
public void entryData(WebDriver driver, String yybm, String priceType, String price, String effectiveTime,
String expiryTime, String xzyj) throws Exception {
WebDriverWait wait = new WebDriverWait(driver, 10);
findelement(driver);
// 输入药易编码
newCode2.sendKeys(yybm);
// 选择价格类型
Select select = new Select(newPriceType);
select.selectByVisibleText(priceType);
// 输入价格
newPrice.sendKeys(price);
// 选择生效日期
newEffectiveTime.click();
// 点击后等待日期控件可见
wait.until(ExpectedConditions
.visibilityOfElementLocated(By.xpath("/html/body/div[8]/div[3]/table/thead/tr[1]/th[2]")));
SelectDate selectDate = new SelectDate();
// 选择生效日期
selectDate.dateSelect(effectiveTime, parentDateWidget.get(0));
// 选择失效日期
selectDate.dateSelect(expiryTime, parentDateWidget.get(1));
// 输入新增依据
newRemarks.sendKeys(xzyj);
}
/**
* 提供保存功能
*
* @param driver
*/
public void save(WebDriver driver) {
findelement(driver);
btnNewSave.click();
}
/**
* 提供取消功能
*
* @param driver
*/
public void cancel(WebDriver driver) {
findelement(driver);
btnNewCancel.click();
}
}
日期控件的html源码:
<div class="datetimepicker datetimepicker-dropdown-bottom-right dropdown-menu" style="left: 770.05px; z-index: 10009; display: block; top: 396.2px;"><div class="datetimepicker-minutes" style="display: none;"><table class=" table-condensed"><thead><tr><th class="prev" style="visibility: visible;"><i class="icon-arrow-left"></i></th><th class="switch" colspan="5">11 10 2016</th><th class="next" style="visibility: visible;"><i class="icon-arrow-right"></i></th></tr></thead><tbody><tr><td colspan="7"><span class="minute">18:00</span><span class="minute active">18:05</span><span class="minute">18:10</span><span class="minute">18:15</span><span class="minute">18:20</span><span class="minute">18:25</span><span class="minute">18:30</span><span class="minute">18:35</span><span class="minute">18:40</span><span class="minute">18:45</span><span class="minute">18:50</span><span class="minute">18:55</span></td></tr></tbody><tfoot><tr><th class="today" colspan="7">今天</th></tr></tfoot></table></div><div class="datetimepicker-hours" style="display: none;"><table class=" table-condensed"><thead><tr><th class="prev" style="visibility: visible;"><i class="icon-arrow-left"></i></th><th class="switch" colspan="5">11 10 2016</th><th class="next" style="visibility: visible;"><i class="icon-arrow-right"></i></th></tr></thead><tbody><tr><td colspan="7"><span class="hour">0:00</span><span class="hour">1:00</span><span class="hour">2:00</span><span class="hour">3:00</span><span class="hour">4:00</span><span class="hour">5:00</span><span class="hour">6:00</span><span class="hour">7:00</span><span class="hour">8:00</span><span class="hour">9:00</span><span class="hour">10:00</span><span class="hour">11:00</span><span class="hour">12:00</span><span class="hour">13:00</span><span class="hour">14:00</span><span class="hour">15:00</span><span class="hour">16:00</span><span class="hour">17:00</span><span class="hour active">18:00</span><span class="hour">19:00</span><span class="hour">20:00</span><span class="hour">21:00</span><span class="hour">22:00</span><span class="hour">23:00</span></td></tr></tbody><tfoot><tr><th class="today" colspan="7">今天</th></tr></tfoot></table></div><div class="datetimepicker-days" style="display: block;"><table class=" table-condensed"><thead><tr><th class="prev" style="visibility: visible;"><i class="icon-arrow-left"></i></th><th class="switch" colspan="5">10 2016</th><th class="next" style="visibility: visible;"><i class="icon-arrow-right"></i></th></tr><tr><th class="dow">日</th><th class="dow">一</th><th class="dow">二</th><th class="dow">三</th><th class="dow">四</th><th class="dow">五</th><th class="dow">六</th></tr></thead><tbody><tr><td class="day old">25</td><td class="day old">26</td><td class="day old">27</td><td class="day old">28</td><td class="day old">29</td><td class="day old">30</td><td class="day">1</td></tr><tr><td class="day">2</td><td class="day">3</td><td class="day">4</td><td class="day">5</td><td class="day">6</td><td class="day">7</td><td class="day">8</td></tr><tr><td class="day">9</td><td class="day">10</td><td class="day active">11</td><td class="day">12</td><td class="day">13</td><td class="day">14</td><td class="day">15</td></tr><tr><td class="day">16</td><td class="day">17</td><td class="day">18</td><td class="day">19</td><td class="day">20</td><td class="day">21</td><td class="day">22</td></tr><tr><td class="day">23</td><td class="day">24</td><td class="day">25</td><td class="day">26</td><td class="day">27</td><td class="day">28</td><td class="day">29</td></tr><tr><td class="day">30</td><td class="day">31</td><td class="day new">1</td><td class="day new">2</td><td class="day new">3</td><td class="day new">4</td><td class="day new">5</td></tr></tbody><tfoot><tr><th class="today" colspan="7">今天</th></tr></tfoot></table></div><div class="datetimepicker-months" style="display: none;"><table class="table-condensed"><thead><tr><th class="prev" style="visibility: visible;"><i class="icon-arrow-left"></i></th><th class="switch" colspan="5">2016</th><th class="next" style="visibility: visible;"><i class="icon-arrow-right"></i></th></tr></thead><tbody><tr><td colspan="7"><span class="month">一月</span><span class="month">二月</span><span class="month">三月</span><span class="month">四月</span><span class="month">五月</span><span class="month">六月</span><span class="month">七月</span><span class="month">八月</span><span class="month">九月</span><span class="month">十月</span><span class="month">十一月</span><span class="month active">十二月</span></td></tr></tbody><tfoot><tr><th class="today" colspan="7">今天</th></tr></tfoot></table></div><div class="datetimepicker-years" style="display: none;"><table class="table-condensed"><thead><tr><th class="prev" style="visibility: visible;"><i class="icon-arrow-left"></i></th><th class="switch" colspan="5">2010-2019</th><th class="next" style="visibility: visible;"><i class="icon-arrow-right"></i></th></tr></thead><tbody><tr><td colspan="7"><span class="year old">2009</span><span class="year">2010</span><span class="year">2011</span><span class="year">2012</span><span class="year">2013</span><span class="year">2014</span><span class="year">2015</span><span class="year active">2016</span><span class="year">2017</span><span class="year">2018</span><span class="year">2019</span><span class="year old">2020</span></td></tr></tbody><tfoot><tr><th class="today" colspan="7">今天</th></tr></tfoot></table></div></div>
对日期控件的所有功能进行封装:
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
public class SelectDate {
/**
* 提供日期的选择功能
*
* @param time
* 日期:例如:2016-6-6,注意年月日首位不要加0
* @param parentElement
* 日期控件的最顶级的父级节点
*/
public void dateSelect(String time, WebElement parentElement) {
// 对年月日以"-"进行切割,日期格式"2016-06-06"
String[] strings = time.split("-");
// 从日的选择切换到月的选择
parentElement.findElement(By.cssSelector(".datetimepicker-days .switch")).click();
// 从月的选择切换到年的选择
parentElement.findElement(By.cssSelector(".datetimepicker-months .switch")).click();
// 开关:用于控制日期向前翻还是向后翻,1为向前翻,2为向后翻
int action = 0;
while (true) {
// 当前年选择页面的年最小值
String minYear = parentElement.findElement(By.cssSelector(".datetimepicker-years .switch")).getText()
.substring(0, 4);
// 当前年选择页面的年最大值
String maxYear = parentElement.findElement(By.cssSelector(".datetimepicker-years .switch")).getText()
.substring(5);
// 当用户选择的年小于当前年选择页面的年最小值时,将开关置为向前
if (Integer.parseInt(strings[0]) < Integer.parseInt(minYear)) {
action = 1;
// 当用户选择的年大于当前年选择页面的年最大值时,将开关置为向后
} else if (Integer.parseInt(strings[0]) > Integer.parseInt(maxYear)) {
action = 2;
// 当用户选择的年在当前年选择页面的最小值与最大值之间时,跳出整个while循环
} else if (Integer.parseInt(minYear) <= Integer.parseInt(strings[0])
&& Integer.parseInt(strings[0]) <= Integer.parseInt(maxYear)) {
break;
}
// 控制年翻页向前向后翻
switch (action) {
case 1:
parentElement.findElement(By.cssSelector(".datetimepicker-years .icon-arrow-left")).click();
break;
case 2:
parentElement.findElement(By.cssSelector(".datetimepicker-years .icon-arrow-right")).click();
break;
}
}
// 获取所有的可选的年
WebElement yearDate = parentElement.findElement(By.cssSelector(".datetimepicker-years td"));
List<WebElement> years = yearDate.findElements(By.tagName("span"));
// 当前可选年范围的最小的年的值
String minData = years.get(0).getText();
// 获取年list的数组下标
int yearIndex = Integer.parseInt(strings[0]) - Integer.parseInt(minData);
// 选择年
years.get(yearIndex).click();
// 获取所有可选的月
WebElement mounthDate = parentElement.findElement(By.cssSelector(".datetimepicker-months td"));
List<WebElement> mounths = mounthDate.findElements(By.tagName("span"));
// 获取月list的数组下标
int mounthIndex = Integer.parseInt(strings[1]) - 1;
// 选择月
mounths.get(mounthIndex).click();
// 获取所有的可选的日,由于webDriver并未提供对单个、多个同一className的定位方法,需要如下处理
WebElement dayData = parentElement.findElement(By.cssSelector(".datetimepicker-days"));
// 获取当月之外的日
List<WebElement> clearDays = dayData.findElements(By.cssSelector(".day.old,.day.new"));
// 获取当前可见的所有的日
List<WebElement> days = dayData.findElements(By.cssSelector(".day"));
// 从当前可见的所有的日中移除当月之外的日,即得到当月所有的日
days.removeAll(clearDays);
// 获取日list的数组下标
int dayIndex = Integer.parseInt(strings[2]) - 1;
// 选择日
days.get(dayIndex).click();
}
}
Webdriver控制翻页控件,并实现向前向后翻页功能,附上代码,仅供参考,其他类似日期控件的功能可以自己封装的更多相关文章
- Unity上一页下一页切换功能实现源码(仅供参考)
在做项目时我们有时需要实现切换上一页下一页图片,切换上一首下一首歌曲等等类似的功能.这里写了个简单的实现源码(仅供参考),要是有更好的方法欢迎提出来,共同进步~ 以切换上一页下一页图片为例: usin ...
- coco2d-x CCScrollView实现背包翻页,仅供参考
#include "CCCGameScrollView.h" USING_NS_CC; USING_NS_CC_EXT; CCCGameScrollView::CCCGameScr ...
- html页面的CSS、DIV命名规则(仅供参考学习)
CSS命名规则: 头:header 内容:content/containe 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制整体布局宽度:wrapper 左右中: ...
- 分享一篇最近新写的jquery注册页面表单校验的程序,仅供参考
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- JQuery datepicker 日期控件设置
datepicker控件可通过参数设置进行语言切换,以下可实现,系统所有日期控件默认为中文,在特定页面或者特定条件下可切换成英语!~ HTML: <!DOCTYPE html> <h ...
- 【前端控件】JQuery datepicker 日期控件设置
datepicker控件可通过参数设置进行语言切换,以下可实现,系统所有日期控件默认为中文,在特定页面或者特定条件下可切换成英语!~ HTML: <!DOCTYPE html> <h ...
- 安卓自定义日期控件(仿QQ,IOS7)
还记得上篇:高大上的安卓日期时间选择器,本篇是根据上篇修改而来,先看下qq中日期选择的效果: 鉴于目前还没有相似的开源日期控件,因此本人花费了一些时间修改了下之前的日期控件,效果如图: 虽说相似度不是 ...
- MVC下使用日期控件
初学MVC,使用日期控件的时候发现不是特别理想,本来是想直接使用JQuery的日期控件的,发现支持的不是很好,type类型要改成date才能使用,而且编辑的时候使用@Html.EditFor也不能绑定 ...
- WPF中ListBox ListView数据翻页浏览笔记(强调:是数据翻页,非翻页动画)
ListBox和ListView在应用中,常常有需求关于每页显示固定数量的数据,然后通过Timer自动或者手动翻页操作,本文介绍到的就是该动作的实现. 一.重点 对于ListBox和ListView来 ...
随机推荐
- 使用recordmydesktop进行屏幕录像
屏幕录像的功能对于分享游戏攻略.演示电脑软件的操作是必不可少的.在Windows下可能一般的用户就下载盗版的商业软件来做了.而在GNU/Linux操作系统下,则有现成的自由软件可供使用,只不过没有图形 ...
- hdu 5901 Count primes 素数计数模板
转自:http://blog.csdn.net/chaiwenjun000/article/details/52589457 计从1到n的素数个数 两个模板 时间复杂度O(n^(3/4)) #incl ...
- NOIP2015-普及组复赛-第一题-金币
题目描述 Description 国王将金币作为工资,发放给忠诚的骑士.第一天,骑士收到一枚金币:之后两天(第二天和第三天),每天收到两枚金币:之后三天(第四.五.六天),每天收到三枚金币:之后四天( ...
- POJ 3253 Fence Repair (优先队列)
POJ 3253 Fence Repair (优先队列) Farmer John wants to repair a small length of the fence around the past ...
- JS定时器设置、快速取消
1.首先定义自己的方法 function test() { alert("开始"); } 2.在定时器中使用 setInterval("test()",1000 ...
- 批处理改hosts
@echo off color 0F @attrib -r "%windir%\system32\drivers\etc\hosts" @echo ######测试配置 beg & ...
- OOP in JS Public/Private Variables and Methods
Summary private variables are declared with the 'var' keyword inside the object, and can only be acc ...
- 属性动画(Property Animation)
属性动画系统是一个强大的可以绘制任意事物.你可以定义改变物体属性的动画,不管它是不是在屏幕上.属性动画随着时间的推移去改变物体的属性.如果要让某个事物动起来,你只需指定该事物的某个属性,如物体的坐标. ...
- ES6 之 let和const命令 Symbol Promise对象
ECMAScript 6入门 ECMAScript 6(以下简称ES6)是JavaScript语言的下一代标准,已经在2015年6月正式发布了. (2016年6月,发布了小幅修订的<ECMASc ...
- 雄冠条码PV系统-2016-05-17-收获
Q1:微信浏览器 input获取焦点时,页面宽度变大 解决方法: HTML <header> 中添加<meta name="viewport" content=& ...