如何使用 selenium webdriver 识别长类名

how to identify the long classname using selenium webdriver

谁能告诉我如何识别硒中的以下元素 webdriver ::

<section id="reports" class="landing-page-column ng-scope" ng-if="requestsForReview &amp;&amp; requestsForReview != 'null' &amp;&amp; requestsForReview.length > 0">

试过了,但在所有实例中都失败了::

final WebElement pendingrequestcolumn = insidepage.findElement(By.id("section#reports.landing-page-column.ng-scope"));

您提到的定位器不是id。您需要使用 By.cssSelector 而不是 By.id

在 HTML 中我可以看到这个元素有 id=reports,所以 By.id("reports") 应该完成工作。

以下定位器之一可以提供帮助

//section[@id='reports' and @class='landing-page-column ng-scope'] - Using AND 

//section[@id='reports' or @class='landing-page-column ng-scope'] - Using OR

//section[contains(@ng-if,'requestsForReview')] - using contains

(//section[@id='reports'])[0] - using Index, starts from 0.Trying changing index value 

例如:(//section[@id='reports'])[X]

这里X取索引值