无法单击 selenium c# 中的 href 元素
Can't click on href element in selenium c#
我需要帮助点击这个元素:
<li class="ui-state-default ui-corner-left ui-tabs-active ui-state-active" role="tab" tabindex="0" aria-controls="tabs-3" aria-labelledby="ui-id-3" aria-selected="true" aria-expanded="true">
<a href="#tabs-3" class="ui-tabs-anchor" role="presentation" tabindex="-1" id="ui-id-3">Prevent propagation</a>
</li>
<!-- edit: missing a li element here? -->
<a href="#tabs-3" class="ui-tabs-anchor" role="presentation" tabindex="-1" id="ui-id-3">Prevent propagation</a>
</li>
我已经尝试 Driver.FindElement().Click;
通过 Xpath,
className
、Link
和 PartialLinkText
。
您尝试导航的 link 似乎与 #tabs-3 元素相关。您可以尝试只执行 driver.Navigate().GoToUrl("URL/#tabs-3");
如果不了解确切的 HTML 以及您在 By classes.
中尝试使用的内容,很难说出为什么您的 FindElement 不起作用
根据上面的代码,这应该可以工作:
var list = driver.FindElements(By.ClassName("ui-tabs-anchor"));
请注意,因为您有多个具有该 class 名称的 Web 元素,您应该返回一个 Web 元素列表 - 访问任何列表元素以实际单击它(list[0].Click( ), 例如).
尝试等待一段时间,直到 link 出现在 DOM
中并变得可点击:
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(20));
wait.Until(ExpectedConditions.ElementToBeClickable(By.LinkText("Prevent propagation"))).Click();
试试下面的代码:
driver.FindElement(By.Xpath("//li[contains(., 'Prevent propagation')]")).click();
我需要帮助点击这个元素:
<li class="ui-state-default ui-corner-left ui-tabs-active ui-state-active" role="tab" tabindex="0" aria-controls="tabs-3" aria-labelledby="ui-id-3" aria-selected="true" aria-expanded="true">
<a href="#tabs-3" class="ui-tabs-anchor" role="presentation" tabindex="-1" id="ui-id-3">Prevent propagation</a>
</li>
<!-- edit: missing a li element here? -->
<a href="#tabs-3" class="ui-tabs-anchor" role="presentation" tabindex="-1" id="ui-id-3">Prevent propagation</a>
</li>
我已经尝试 Driver.FindElement().Click;
通过 Xpath,
className
、Link
和 PartialLinkText
。
您尝试导航的 link 似乎与 #tabs-3 元素相关。您可以尝试只执行 driver.Navigate().GoToUrl("URL/#tabs-3");
如果不了解确切的 HTML 以及您在 By classes.
中尝试使用的内容,很难说出为什么您的 FindElement 不起作用根据上面的代码,这应该可以工作:
var list = driver.FindElements(By.ClassName("ui-tabs-anchor"));
请注意,因为您有多个具有该 class 名称的 Web 元素,您应该返回一个 Web 元素列表 - 访问任何列表元素以实际单击它(list[0].Click( ), 例如).
尝试等待一段时间,直到 link 出现在 DOM
中并变得可点击:
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(20));
wait.Until(ExpectedConditions.ElementToBeClickable(By.LinkText("Prevent propagation"))).Click();
试试下面的代码:
driver.FindElement(By.Xpath("//li[contains(., 'Prevent propagation')]")).click();