How to search an specific button in a grid using webdriverIO

柔情痞子 提交于 2019-12-12 06:59:10

问题


I'm using an ExtJS grid panel. This grid has more than 20 rows of info and I want to search in each row for an icon that represents active mode, using WebdriverIO as a test driver.

How can I search in each row till the test driver finds the first active icon? (Note: the grid I'm testing is hosted on alegra.com).

Consider the following HTML print-screen:


回答1:


It's hard to know exactly how to do it without knowing which locator you are using but if you first get a list of the rows and then filter them and grab the first match it should do what you are looking for.

public static get rows() { return browser.elements('#someTableId > table > tbody > tr'); }

public static getFirstMatch() {
    return this.rows.value.filter((row: WebdriverIO.Element) =>
        browser.elementIdElement(row.ELEMENT, 'someLocator').value)[0];
}



回答2:


This is how i did it

var icon_type = 'delete';

it('Se elimina una factura', function(){        
        //rellenamos el array de elementos del grid
    var elements = browser.getAttribute('#gridInvoices #gridview-1047-table tbody tr .action-icons img:nth-child(7)','class');
        //Busca la primera coincidencia en el array con type
    var row_num = elements.indexOf(icon_type);

    if(row_num === -1){
        throw new Error('No se encontraron botones activos del tipo "Eliminar" en todo el grid' )
    }else{
        $$('#gridInvoices #gridview-1047-table tbody tr')[row_num].click('.action-icons [title="Eliminar"]');
        browser.click('=Sí')
        };  
});


来源:https://stackoverflow.com/questions/44877856/how-to-search-an-specific-button-in-a-grid-using-webdriverio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!