选择最后一行。然后可能向后迭代

时间:2014-05-20 18:17:54

标签: javascript selenium selenium-webdriver

在这里得到了很棒的帮助,我想我会要求更多。我有一个屏幕,作为随机数量的可点击链接行。我需要单击此列表的最后一行。然后找出它是否是正确的。如果没有,那么返回,选择第2行到最后一行,然后选择第3行到最后一行等。直到我找到我想要的或者用完行。

不幸的是,每一行都有相同的名称。我必须点击它以查明它是否是我想要的行。

以下是其中一行的示例:

<a href="javascript:void(0)" role="button" dojoattachpoint="subject" dir="ltr" aria-labelledby="taskrowsubjectcom_ibm_bpm_social_widgets_task_list_TaskRow_19" title="Click to work on the task">Request Full Quotes from Supplier: Supplier One</a>

唯一的区别是TaskRow之后的数字。有什么帮助吗?

以下是该行之前的一些代码:

<div id="dueToday" class="bpm-task-list-category dijitTitlePane" title="" role="group" widgetid="dueToday" aria-label="Due Today (2)" style="display: block;">
<div class="dijitTitlePaneTitle dijitOpen" dojoattachpoint="titleBarNode" dojoattachevent="onclick:_onTitleClick, onkeypress:_onTitleKey">
<div class="dijitTitlePaneContentOuter" role="presentation" dojoattachpoint="hideNode">
<div class="dijitReset" role="presentation" dojoattachpoint="wipeNode" style="height: auto;">
<div id="dueToday_pane" class="dijitTitlePaneContentInner" role="presentation" dojoattachpoint="containerNode" aria-hidden="false">
<div>
<div id="com_ibm_bpm_social_widgets_task_list_TaskRow_2" class="bpm-social-task-row" widgetid="com_ibm_bpm_social_widgets_task_list_TaskRow_2" style="display: block;">
<div id="com_ibm_bpm_social_widgets_task_list_TaskRow_1" class="bpm-social-task-row" widgetid="com_ibm_bpm_social_widgets_task_list_TaskRow_1" style="display: block;">
<div class="bpm-social-task-box" dojoattachpoint="taskBoxAttach">
<div class="bpm-social-task-row-status-img-div">
<div class="bpm-social-task-row-data-div" role="listitem" tabindex="0" dojoattachevent="ondijitclick:toggle" dojoattachpoint="focusNode">
<div class="bpm-social-task-row-data-header">
<span class="bpm-social-task-row-data-subject">
<div id="taskrowsubjectcom_ibm_bpm_social_widgets_task_list_TaskRow_1" style="display:none" dojoattachpoint="headerLabel">Task subject</div>
<a href="javascript:void(0)" role="button" dojoattachpoint="subject" dir="ltr" aria-labelledby="taskrowsubjectcom_ibm_bpm_social_widgets_task_list_TaskRow_1" title="Click to work on the  task">Request Full Quotes from Supplier: Supplier One</a>
</span>
<div class="bpm-social-drop-down" wairole="button" style="display: block;" tabindex="0" dojoattachpoint="menuButton" role="button" aria-label="Actions" _dijitmenucom_ibm_bpm_social_widgets_actiondropdownmenu_41="1">
<span class="bpm-social-task-row-data-due" dojoattachpoint="due">
<span class="bpm-social-task-row-data-complete" dojoattachpoint="complete">
</div>

谢谢! 格雷格

1 个答案:

答案 0 :(得分:0)

您可以使用:last-child选择器执行此操作:

a:last-child[aria-labelledby^='taskrowsubject']

使用更完整的HTML,我能够提出这个xpath:

(//a[contains(@aria-labelledby, 'TaskRow')])[last()]