简体   繁体   中英

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 ?

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:

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不可用,则可以使用xpath或css。如果无法自己编写它们,则可以使用firebug和xpath checker之类的工具。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM