实现元素左移右移

上一篇 / 下一篇  2013-08-13 19:01:29 / 个人分类:selenium

面朝大海,春暖花開......
场景:导航栏上显示模块名称,右击,左击,每点击一次,导航栏上的元素若超过3个,则移动3个。否则有几个,移动几个。
思路:移动一次,导航栏上的元素的下标(index)会相应移动,在【1,7】之间的,可以取到元素,若其他区间的,则会隐藏在左边或者隐藏在右边。所以若想点击到该元素,则必须要让元素移动到范围【1,7】。这里设定了一个参数:counter,来记录相对于原始下标【1,2,3,4,5,6,7】,此时元素应该要移动多少位,才能被取到。
 
public class NaviModule{
      private int counter=0;
      /**
     *find the module's index and name into map.
    *@paramcounter; the index +-3 when perform. "leftMove()"/rightMove()
    *@paramname; the module's name
     *return the index of module.
     public int index(String name,int counter){
           int index=0;
           int num=NaviBarPage.navigationModules().size();
           Map<Integer,String>map=new HashMap<Integer,String>;
           for(ing i=1;i<num+1;i++){
           WebElement td=Table.getCell(By.xpath("xxx"));
           String text=td.getText();
           int j=i-counter;
           map.put(j,text);
          }
       for(int j=1-counter;j<num+1-counter;j++){
         i(map.get(j).equals(name)){
         index=j;
         break;
        }
       return index;
       } 
}
 

TAG:

 

评分:0

我来说两句

Open Toolbar