C# 无法单击元素XPath
这就是我想要达到的目标:C# 无法单击元素XPath,c#,selenium,xpath,C#,Selenium,Xpath,这就是我想要达到的目标: <div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"> <div class="ui-dialog-buttonset"> <button style="background-color: rgb(218, 218, 218);" aria-disabled="false" role="button" class="ui-button ui-
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
<button style="background-color: rgb(218, 218, 218);" aria-disabled="false" role="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button">
<span style="background-color: transparent;" class="ui-button-text">OK</span>
</button>
</div>
</div>
我使用了Selenium IDE的find element功能,使用xpath,它可以找到元素。表达式中不需要xpath=部分:
driver.FindElement(By.XPath("//span[contains(@class,'ui-button-text')][contains(text(),'OK')])")).Click();
此外,我认为您可以停止使用contains()
,并检查完整的类和text()
值:
driver.FindElement(By.XPath("//span[@class = 'ui-button-text' and . = 'OK'])")).Click();
这里
引用元素的文本。表达式中不需要xpath=
部分:
driver.FindElement(By.XPath("//span[contains(@class,'ui-button-text')][contains(text(),'OK')])")).Click();
此外,我认为您可以停止使用contains()
,并检查完整的类和text()
值:
driver.FindElement(By.XPath("//span[@class = 'ui-button-text' and . = 'OK'])")).Click();
这里的
引用元素的文本。其他解决方案是使用此xpath:
driver.FindElement(By.XPath("///div[@class='ui-dialog-buttonset']/button/span")).Click();
另一种解决方案是使用此xpath:
driver.FindElement(By.XPath("///div[@class='ui-dialog-buttonset']/button/span")).Click();
如果需要精确的解决方案:
您可以使用以下选项:
如果需要精确的解决方案:
您可以使用以下选项:
虽然,必要的警告,如果类可能包含更多的类,您将不得不使用contains()。虽然,必要的警告,如果类可能包含更多的类,您将不得不使用contains()。这篇文章是两年前写的,我想他们现在明白了,或者重新编写了应用程序。:)这篇帖子是两年前写的,我想他们现在已经明白了,或者重新编写了应用程序。:)