Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法单击元素XPath_C#_Selenium_Xpath - Fatal编程技术网

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()。这篇文章是两年前写的,我想他们现在明白了,或者重新编写了应用程序。:)这篇帖子是两年前写的,我想他们现在已经明白了,或者重新编写了应用程序。:)