2017-09-21 47 views
1

EXT视图页面如何获得浏览器的Ext JS元素ID或价值的itemId检查

text : ACTIONS, 
xtype : 'actioncolumn', 
draggable: false, 
dataIndex: 'message', 
items: 
{ 
    [ 
    { 
     glyph:'[email protected]', 
     name : 'edit_customer', 
     handler: function(grid, rowIndex, colIndex, item, event, record, row) 
     { 
     this.up("customer-list").getController().EditCustomer(record); 
     }, 
     } 
    ] 
    } 

HTML输出:

<span role="button" title="" 
class="x-action-col-icon x-action-col-glyph x-action-col-6 x-hide-display" 
style="font-family:FontAwesome" 
data-qtip="Edit Customer"></span> 

但我要在这里把我的ID。

如果刷新按钮的ID将comeing差异数

对于实例页面:ID = “的tableview-1738”

那么如何才能得到ID或driectly html页面的任何attrbute。 我需要在此元素中测试自动化

+0

你想获取处理函数吗? –

+0

不,我不想要蚂蚁功能只是在检查元素得到id意味着id值 –

+0

对不起,我没有得到你 –

回答

0

ExtJS中的ID是动态的。所以你必须使用标签字符串或者你的网页设计来获取元素。以下是根据标签和字段类型获取元素ID的代码。

private static String getID(WebDriver driver, String elementText, String field_type, Integer occurence) throws InterruptedException { 

    String pageSource = driver.getPageSource(); 
    String regX = "<" + field_type + " id=\"([^\"]+)\" [^>]+>" + elementText + "<\\/" + field_type + ">"; 
    Pattern id = Pattern.compile(regX); 
    Matcher match = id.matcher(pageSource); 
    int count = 0; 

    while (count < occurence) { 
     count++; 
     match.find(); 
     switch (field_type) { 
     case "label": 
      returnID = match.group(1).replace("label", "input"); 
      break; 
     case "span": 
      returnID = match.group(1).replace("btnInnerEl", "btnIconEl"); 
      break; 

     } 
    } 
    return returnID; 
} 

Fn调用获取带有标签“密码”的文本字段的ID。

element = driver.findElement(By.id(ElementFinder.getID(driver, "Password", "label",1))); 
相关问题