如何使用Selenium和C#使用href属性识别元素

问题描述 投票:0回答:1

我在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:'陈旧元素reference:元素未附加到页面文档(会话信息:chrome = 83.0.4103.61)'

c# selenium xpath css-selectors webdriverwait
1个回答
0
投票
从细节上没有定论,为什么会看到

StaleElementReferenceException

。但是,该元素是Angular元素,并且在<span>元素的子<a>标记内。因此,您必须为所需的ElementToBeClickable()引入WebDriverWait
© www.soinside.com 2019 - 2024. All rights reserved.