是否有一个 puppeteer 函数来检索具有相同选择器的所有元素,并且不是同时单击每个元素,而是一个接一个地单击它们? ()
Is there a puppeteer function to retrieve all elements with the same selector and click on them not each one on the same time but one by one? ()
我一周前开始学习木偶戏。
我必须通过 angular 及其 ng-repeat 完成的网格。我不能修改这个网格,所以如果你有一个需要修改网格的解决方案,不幸的是这是不可能的。网格正是我在这个 post 添加的最后一个片段中的那个。
我的目标是检索所有由选择器“[title="Titolo FD"]”标识的 img 按钮,然后单击第一个,对打开的 window 进行相同的操作,关闭 window,然后点击第二个按钮,对第一个按钮做同样的操作,关闭第二个window,点击第三个按钮,依此类推。
我试过下面这段代码
for(let i = 0; i < 10; i++){
try {
await page.waitForSelector('[title="Titolo FD"]');
let list = await page.$$('[title="Titolo FD"]');
let results = [];
for (let j = 0; j < list.length; j++) {
results.push(await (await list[j].getProperty('outerHTML')).jsonValue())
}
await results[i].click(); // this function here doesn't work for me
} catch (e) {
console.error(Console.FgRed, e.message);
}
await page.waitForTimeout(600);
}
有了这个我可以检索我需要但不能点击它们的按钮列表。
这是我的网格。
<div class="ui-grid-canvas">
<!-- ngRepeat: (rowRenderIndex, row) in rowContainer.renderedRows track by $index -->
<div ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" class="ui-grid-row ng-scope" ng-style="Viewport.rowStyle(rowRenderIndex)" ng-class="{'ui-grid-row-selected': row.isSelected}">
<div ui-grid-row="row" row-render-index="rowRenderIndex" class="ng-isolate-scope">
<!-- ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-005" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-scope">
<img src="/path/images/find.gif" ng-click="grid.appScope.btnClick3(row.entity.CId)" class="bottoneGriglia" title="TITOLO">
<img src="/path/images/img2.png" ng-click="grid.appScope.btnClick4(row.entity.CId)" class="bottoneGriglia" title="TITOLO FD"></div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-006" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">00001</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-007" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">Tipo A</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-008" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">AC</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-009" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">CL</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00A" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">cf</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00B" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">02/10/2008 15:18:07</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00C" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-scope" title="Visualizza 1">
<a class="wx_link_button_blue ng-binding" href="javascript:void(0)" ng-click="grid.appScope.btnAzione1(row.entity)">6</a><a></a></div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00D" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-scope" title="Visualizza 2">
<a class="wx_link_button_blue ng-binding" href="javascript:void(0)" ng-click="grid.appScope.btnAzione2(row.entity)">183</a><a></a></div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid --></div></div><!-- end ngRepeat: (rowRenderIndex, row) in rowContainer.renderedRows track by $index -->
<div ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" class="ui-grid-row ng-scope" ng-style="Viewport.rowStyle(rowRenderIndex)" ng-class="{'ui-grid-row-selected': row.isSelected}">
<div ui-grid-row="row" row-render-index="rowRenderIndex" class="ng-isolate-scope">
<!-- ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-005" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-scope">
<img src="/path/images/find.gif" ng-click="grid.appScope.btnClick3(row.entity.CId)" class="bottoneGriglia" title="TITOLO">
<img src="/path/images/img2.png" ng-click="grid.appScope.btnClick4(row.entity.CId)" class="bottoneGriglia" title="TITOLO FD"></div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-006" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">00002</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-007" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">Tipo B</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-008" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">AC</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-009" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">F SRL</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00A" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">piva</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00B" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">26/10/2008 18:45:15</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00C" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-scope" title="Visualizza 1">
<a class="wx_link_button_blue ng-binding" href="javascript:void(0)" ng-click="grid.appScope.btnAzione1(row.entity)">3</a><a></a></div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00D" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-scope" title="Visualizza 2">
<a class="wx_link_button_blue ng-binding" href="javascript:void(0)" ng-click="grid.appScope.btnAzione2(row.entity)">5</a><a></a></div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid --></div></div><!-- end ngRepeat: (rowRenderIndex, row) in rowContainer.renderedRows track by $index -->
<<row 3>>
...
<<row N>>
</div>
谢谢大家!
我相信您打算单击 list
中的页面元素,而不是 results
中的字符串元素,如下所示:
await list[i].click();
我一周前开始学习木偶戏。 我必须通过 angular 及其 ng-repeat 完成的网格。我不能修改这个网格,所以如果你有一个需要修改网格的解决方案,不幸的是这是不可能的。网格正是我在这个 post 添加的最后一个片段中的那个。
我的目标是检索所有由选择器“[title="Titolo FD"]”标识的 img 按钮,然后单击第一个,对打开的 window 进行相同的操作,关闭 window,然后点击第二个按钮,对第一个按钮做同样的操作,关闭第二个window,点击第三个按钮,依此类推。
我试过下面这段代码
for(let i = 0; i < 10; i++){
try {
await page.waitForSelector('[title="Titolo FD"]');
let list = await page.$$('[title="Titolo FD"]');
let results = [];
for (let j = 0; j < list.length; j++) {
results.push(await (await list[j].getProperty('outerHTML')).jsonValue())
}
await results[i].click(); // this function here doesn't work for me
} catch (e) {
console.error(Console.FgRed, e.message);
}
await page.waitForTimeout(600);
}
有了这个我可以检索我需要但不能点击它们的按钮列表。
这是我的网格。
<div class="ui-grid-canvas">
<!-- ngRepeat: (rowRenderIndex, row) in rowContainer.renderedRows track by $index -->
<div ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" class="ui-grid-row ng-scope" ng-style="Viewport.rowStyle(rowRenderIndex)" ng-class="{'ui-grid-row-selected': row.isSelected}">
<div ui-grid-row="row" row-render-index="rowRenderIndex" class="ng-isolate-scope">
<!-- ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-005" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-scope">
<img src="/path/images/find.gif" ng-click="grid.appScope.btnClick3(row.entity.CId)" class="bottoneGriglia" title="TITOLO">
<img src="/path/images/img2.png" ng-click="grid.appScope.btnClick4(row.entity.CId)" class="bottoneGriglia" title="TITOLO FD"></div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-006" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">00001</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-007" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">Tipo A</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-008" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">AC</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-009" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">CL</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00A" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">cf</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00B" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">02/10/2008 15:18:07</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00C" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-scope" title="Visualizza 1">
<a class="wx_link_button_blue ng-binding" href="javascript:void(0)" ng-click="grid.appScope.btnAzione1(row.entity)">6</a><a></a></div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00D" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-scope" title="Visualizza 2">
<a class="wx_link_button_blue ng-binding" href="javascript:void(0)" ng-click="grid.appScope.btnAzione2(row.entity)">183</a><a></a></div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid --></div></div><!-- end ngRepeat: (rowRenderIndex, row) in rowContainer.renderedRows track by $index -->
<div ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" class="ui-grid-row ng-scope" ng-style="Viewport.rowStyle(rowRenderIndex)" ng-class="{'ui-grid-row-selected': row.isSelected}">
<div ui-grid-row="row" row-render-index="rowRenderIndex" class="ng-isolate-scope">
<!-- ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-005" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-scope">
<img src="/path/images/find.gif" ng-click="grid.appScope.btnClick3(row.entity.CId)" class="bottoneGriglia" title="TITOLO">
<img src="/path/images/img2.png" ng-click="grid.appScope.btnClick4(row.entity.CId)" class="bottoneGriglia" title="TITOLO FD"></div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-006" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">00002</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-007" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">Tipo B</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-008" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">AC</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-009" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">F SRL</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00A" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">piva</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00B" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-binding ng-scope">26/10/2008 18:45:15</div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00C" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-scope" title="Visualizza 1">
<a class="wx_link_button_blue ng-binding" href="javascript:void(0)" ng-click="grid.appScope.btnAzione1(row.entity)">3</a><a></a></div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid -->
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell ng-scope ui-grid-coluiGrid-00D" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
<div class="ui-grid-cell-contents ng-scope" title="Visualizza 2">
<a class="wx_link_button_blue ng-binding" href="javascript:void(0)" ng-click="grid.appScope.btnAzione2(row.entity)">5</a><a></a></div></div>
<!-- end ngRepeat: (colRenderIndex, col) in colContainer.renderedColumns track by col.uid --></div></div><!-- end ngRepeat: (rowRenderIndex, row) in rowContainer.renderedRows track by $index -->
<<row 3>>
...
<<row N>>
</div>
谢谢大家!
我相信您打算单击 list
中的页面元素,而不是 results
中的字符串元素,如下所示:
await list[i].click();