我正在尝试使用selenium测试添加和删除博客帖子。我们系统中已经有一些博客条目,我不想删除,只有我创建的条目。因此,在下面的示例中,您将看到“我的博客”后跟名称=“ctl00 $ ctl00 $ OuterTaskRegion $ TaskRegion $ TaskRegion $ PostList1 $ theposts $ ctl02 $ DeleteButton”value =“Delete” 然后是另一个博客项目,然后是删除。我想在“我的博客”
之后点击删除按钮 <tr>
<td class="CommonListCellLeftMost">
<span><a href/2015/05/15/my-blog.aspx">
My blog </a></span>
<div style="font-size:.8em; color:#959595">
Drafted by
QATest1
on
May 15, 2015
at
2:32 PM
</div>
</td>
<td class="CommonListCell PostViewsCell">
<a href="/cs/controlpanel/blogs/views.aspx? WeblogID=103&WeblogPostID=131221">
0</a>
</td>
<td class="CommonListCell PostCommentsCell">
<a href="/cs/controlpanel/blogs/comments.aspx?WeblogID=103&WeblogPostID=131221">
0</a>
</td>
<td class="CommonListCell PostImageStatusCell">
<img src="/cs/unpublished.gif"
title="Unpublished"/>
</td>
<td class="CommonListCell" nowrap="nowrap">
<input type="button" onclick="window.location='/posteditor.aspx"value="Edit" />
<input type="submit" name="ctl00$ctl00$OuterTaskRegion$TaskRegion$TaskRegion$PostList1$theposts$ctl02 $DeleteButton" value="Delete" onclick="return confirm('Delete? \n(this action cannot be undone)');" id="ctl00_ctl00_OuterTaskRegion_TaskRegion_TaskRegion_PostList1_theposts_ctl02_D eleteButton" />
</td>
</tr>
<tr class="AltListRow">
<td class="CommonListCellLeftMost">
<span><a href="/cs/community/b/blog/archive/2015/05/12/not- mine.aspx">
not mine</a></span>
<div style="font-size:.8em; color:#959595">
Published by
QAguestB
on
May 12, 2015
at
4:05 PM
</div>
</td>
<td class="CommonListCell PostViewsCell">
<a href="/cs/controlpanel/blogs/views.aspx? WeblogID=103&WeblogPostID=131216">
8</a>
</td>
<td class="CommonListCell PostCommentsCell">
<a href="/cs/controlpanel/blogs/comments.aspx? WeblogID=103&WeblogPostID=131216">
0</a>
</td>
<td class="CommonListCell PostImageStatusCell">
<img src="/cs/controlpanel/images/comment/published.gif"
title="Published"/>
</td>
<td class="CommonListCell">
<input type="button" onclick="window.location='/cs/controlpanel/blogs/posteditor.aspx? SelectedNavItem=Posts&WeblogID=103&WeblogPostID=131216';" value="Edit" />
<input type="submit" name="ctl00$ctl00$OuterTaskRegion$TaskRegion$TaskRegion$PostList1$theposts$ctl03 $DeleteButton" value="Delete" onclick="return confirm('Are you sure you want to delete this post? \n(this action cannot be undone)');" id="ctl00_ctl00_OuterTaskRegion_TaskRegion_TaskRegion_PostList1_theposts_ctl03_D eleteButton" />
</td>
</tr>
答案 0 :(得分:1)
您可以使XPath表达式检查My Blog
文本并找到删除按钮:
//tr[contains(td/span/a, "My blog")]/td/input[@value = "Delete"]