简体   繁体   English

识别Selenium自动化的页面元素

[英]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.

相关问题 使用硒从html页面中识别聚类元素 - identifying clustered element from a html page using selenium Python/Selenium 识别元素问题 - Python/Selenium Identifying an element issue 在Selenium中标识具有相同类名的Web元素 - Identifying the Web element with same class name in Selenium 硒不能识别特定HTML中的任何元素,为什么? - Selenium not identifying any element in particular HTML, why? 使用 Selenium 识别 Select 元素的 ElementNotInteractableException 错误 - ElementNotInteractableException error identifying a Select element using Selenium 在Selenium WebDriver中标识元素时出现错误 - Getting Error while identifying an element in Selenium WebDriver 使用Selenium和java识别页面中的iframe数量? - Identifying number of iframes in a page using Selenium with java? 如果在页面上找不到元素,我的Selenium Automation脚本将继续搜索元素。 我该如何解决这个问题 - My Selenium Automation script keeps on searching the Element, if its not found on the Page. How do i resolve this issue 保存后自动更新时如何识别Selenium页面中的元素?(与自动化有关) - How to identify an element in a page in Selenium, when it gets auto updated after save?(automation related) 当我们登陆页面时如何点击 DOM 上不可用的元素。 JAVA + Selenium 自动化 - How to click on element which is not available on DOM when we land on the page. JAVA + Selenium Automation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM