我在href上选择时遇到问题
<a id="1 - GovSearch" name="1 - GovSearch" title="Population and Immigration Authority"
href="https://www.gov.il/en/Departments/population_and_immigration_authority" class="content-title
first-result" ng-class="{ 'first-result': $first }">
<!-- ngIf: item.Extension -->
<span ng-class="item.SubTitle ? 'pipe-after':''" class="ng-
binding"> Population and Immigration Authority </span>
<!-- ngIf: item.SubTitle -->
</a>
我尝试使用linktext并出现错误:
element.FindElement(By.LinkText("Population and Immigration Authority")).Click();
出现此错误:
OpenQA.Selenium.StaleElementReferenceException: 'stale element reference: element is not attached to the page document (Session info: chrome=83.0.4103.61)'
StaleElementReferenceException
。但是,该元素是Angular元素,并且在<span>
元素的子<a>
标记内。因此,您必须为所需的ElementToBeClickable()
引入WebDriverWait