[英]Identifying a page element for Selenium automation
I have a Application Under Test that has a tabular structure like below: 我有一个具有如下表格结构的被测应用程序:
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="background-color: White">
<tbody>
<tr>
<td id="lefthandcol" class="b24-lefthandcol" valign="top" style="width: 130px !important">
<td style="height: 400px; width: 5px">
<td style="height: 400px; width: 5px">
<td valign="top">
<div id="ctl00_ContentPlaceHolder1_MiddlePanel">
<div id="DestinationDiv"></div>
<table>
</td>
<td style="height: 400px; width: 5px">
<td style="height: 400px; width: 5px">
<td width="225" valign="top" align="right" style="background-color: White;">
</tr>
</tbody>
</table>
The question is how do I identify this table since it doesn't have id
? 问题是由于没有
id
如何识别此表?
What is generally people do in such scenario? 人们在这种情况下通常会做什么?
You should find any unique parent-children relationship and write it with the help of CSS or Xpath: 您应该找到任何唯一的父子关系,并借助CSS或Xpath编写它:
IWebElement table = driver.FindElement(By.XPath("//table[descendant::*[@id='ctl00_ContentPlaceHolder1_MiddlePanel']]"));
So the table with descendant element with id=ctl00_ContentPlaceHolder1_MiddlePanel
will be found. 因此,将找到带有后代元素
id=ctl00_ContentPlaceHolder1_MiddlePanel
的表。
如果id不可用,则可以使用xpath或css。如果无法自己编写它们,则可以使用firebug和xpath checker之类的工具。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.