我们将protractorjs和node用于我们的测试自动化。因为我们有两个面向客户的Web应用程序,那就是ReactJS应用程序,它在我们使用此框架的那些元素上具有非常敏感的元素。在面向代理的应用程序中,我们有一个包含普通html表的页面。我试图匹配我选择的文本,然后双击以打开一个模型框。我能够找到表上的行数,但无法转到我选择的确切行。有人可以用任何protractorjs函数来帮助我吗?
在这种情况下,我需要导航到“ ETHBTC”并双击以在新的弹出模型框中打开其详细信息。
页面元素
<table class="table">
<thead>
<tr>
<th>Instrument ID</th>
<th>Symbol</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>BTCUSD</td>
<td>Running</td>
<tr>
<td>2</td>
<td>ETHBTC</td>
<td>Running</td>
<tr>
<td>3</td>
<td>ETHGBP</td>
<td>Running</td>
</tr>
</tbody>
</table>
屏幕图片
代码: 获取行数后,不知道如何遍历所需的行并选择该行。我知道我们必须使用for循环遍历,但是不要匹配预期的循环。
const service_table = element(by.css('.table'))
let table_rows = service_table.element.all(by.tagName('tbody')).all(by.tagName('tr'))
let rows_count = table_rows.count()
已更新
这是我在表格行上双击活动的全部方法
async open_exchange_service(data) {
await browser.sleep(1000)
const service_table = await element(by.css('.table'));
const table_row = await service_table.element(by.cssContainingText('tbody tr td', data));
try {
console.log('i am in tryyyyyyyy loooppppp')
await browser.actions().click(table_row).perform().then(() => browser.actions().click(table_row).perform());
// await browser.actions().
// mouseMove(table_row).
// doubleClick().
// perform();
// await browser.actions().
// mouseMove(table_row).
// doubleClick().
// perform();
} catch (error) {
console.log('i am in catchhhhhh looppppp')
const service_table = await element(by.css('.table'));
const table_row = await service_table.element(by.cssContainingText('tbody tr td', data));
await browser.actions().click(table_row).perform().then(() => browser.actions().click(table_row).perform());
// await browser.actions().
// mouseMove(table_row).
// doubleClick().
// perform();
// await browser.actions().
// mouseMove(table_row).
// doubleClick().
// perform();
}
}
async open_exchange_instrument(data) {
await browser.sleep(1000)
const service_table = await element(by.css('.table'));
const table_row = await service_table.element(by.cssContainingText('tbody tr td', data));
try {
console.log('i am in tryyyyyyyy loooppppp')
await browser.actions().click(table_row).perform().then(() => browser.actions().click(table_row).perform());
// await browser.actions().doubleClick(table_row).perform();
// await browser.actions().doubleClick(table_row).perform();
} catch (error) {
console.log('i am in catchhhhhh looppppp')
await browser.sleep(500)
const service_table = await element(by.css('.table'));
const table_row = await service_table.element(by.cssContainingText('tbody tr td', data));
await browser.executeScript('arguments[0].scrollIntoView(true);', table_row);
await browser.actions().click(table_row).perform().then(() => browser.actions().click(table_row).perform());
// await browser.actions().doubleClick(table_row).perform();
// await browser.actions().doubleClick(table_row).perform();
}
}
答案 0 :(得分:0)
您可以使用cssContainingText
通过文本标识特定行:
const service_table = $('.table'));
const table_row = service_table.element(by.cssContainingText('tbody tr td', 'ETHBTC'));
browser.actions().doubleClick(table_row).perform();