• selenium用java找到表格某一行某一列中含有特定文字的某个元素


    html部分代码如下:

    [html] view plain copy
     
    1. <tbody>  
    2.          <tr class="odd">  
    3.             <td>1609</td>  
    4.             <td>-YOUKU-begin</td>  
    5.             <td>firstAgent</td>  
    6.             <td</td>  
    7.             <td</td>  
    8.             <td>2015-09-16 17:02:55</td>  
    9.             <td><span class="stop" ref="1609" id="change_status"></span>stop </td>  
    10.             <td class="mtbuttons"><href="javascript:;">permission</a> | <href="/code/index.php?r=update&id=1609">edit</a</td>  
    11.          </tr>  
    12.          <tr class="even selected">  
    13.             <td>1594</td>  
    14.             <td>-YOUKU</td>  
    15.             <td>firstAgent</td>  
    16.             <td</td>  
    17.             <td</td>  
    18.             <td>2015-09-16 17:02:55</td>  
    19.             <td><span class="stop" ref="1594" id="change_status"></span>stop </td>  
    20.             <td class="mtbuttons"><href="javascript:;">permission</a> | <href="/code/index.php?r=update&id=1594">edit</a</td>  
    21.          </tr>  
    22.          <tr class="odd">  
    23.             <td>1593</td>  
    24.             <td>-YOUKU-first</td>  
    25.             <td>firstAgent</td>  
    26.             <td</td>  
    27.             <td</td>  
    28.             <td>2015-09-16 17:02:55</td>  
    29.             <td><span class="stop" ref="1593" id="change_status"></span>stop </td>  
    30.             <td class="mtbuttons"><href="javascript:;">permission</a> | <href="/code/index.php?r=update&id=1593">edit</a</td>  
    31.          </tr>  
    32.       </tbody>  

    找到列中有1594这个值的行,然后点击edit链接

    [java] view plain copy
     
    1. List<WebElement> trlist=driver.findElements(By.xpath("//div[@id='company-grid']/table/tbody/tr"));  
    2.             for(int r=0;r<trlist.size();r++){  
    3.                 String trText=trlist.get(r).getText();  
    4.                 if(trText.contains("1594")){  
    5.                     trlist.get(r).findElement(By.xpath("(.//a[contains(text(),'edit')])[2]")).click();  
    6.                       
    7.                     break;  
    8.                 }  
    9.                   
    10.             }  
  • 相关阅读:
    Email:2017
    mac下使用QuickTime录屏及上传youku注意事项
    unity, 自定义类中使用print
    unity, 集成iOS广告sdk注意事项
    xcode,不要将.a文件拖到xcode里
    unity, 慎用DontDestroyOnLoad
    unity, 弹出panel一定要放在UI Hierarchy的底端
    unity, iOS下画面错乱解法
    (转)NSString to string(支持中文)
    objective-c的观察者模式
  • 原文地址:https://www.cnblogs.com/ceshi2016/p/7650700.html
Copyright © 2020-2023  润新知