Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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/8/selenium/4.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
什么';Selenium XPath和FF XPath之间的区别是什么?_Xpath_Selenium - Fatal编程技术网

什么';Selenium XPath和FF XPath之间的区别是什么?

什么';Selenium XPath和FF XPath之间的区别是什么?,xpath,selenium,Xpath,Selenium,我正在为我们的web应用程序编写一些测试。当我在Firefox XPath Checker插件中使用此XPath时,它可以正常工作: //div[contains(@class, "my-class") and @data-custom-attr="id")] 但如果在selenium代码中这样使用: (new WebDriverWait(driver, MAX_TIMEOUT_FOR_ELEMENT_LOADING_IN_SECONDS)).until(ExpectedConditions.

我正在为我们的web应用程序编写一些测试。当我在Firefox XPath Checker插件中使用此XPath时,它可以正常工作:

//div[contains(@class, "my-class") and @data-custom-attr="id")]
但如果在selenium代码中这样使用:

(new WebDriverWait(driver, MAX_TIMEOUT_FOR_ELEMENT_LOADING_IN_SECONDS)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[contains(@class, \"my-class\") and @data-custom-attr=\"id\")]"));
出现超时异常

为什么xpath查询直接在浏览器中工作,而不在selenium测试中工作?是否有我必须考虑的文件?


作为旁注:如果我使用确切的路径/html/body/div/。。。等等,它确实有效。我上面的示例中的css选择器挂件也不起作用。

它应该起作用,您在代码中给出的最大等待时间是多少。

我们需要查看您正在测试的页面的副本,或者在面向公众的站点上运行它。您可以将该XPath弹出到Selenium IDE中,并查看它的功能。它在IFrame中吗?可能问题不在于定位元素,而在于时间。以秒为单位加载元素的最大超时值是多少?元素出现的时间是否足够?10秒就足够了。当我在本地浏览器上运行它时,我看到了元素。在我看来,Selenium中的XPath解析器被属性名中的“-”所困扰。如果我在FF中的Xpath插件中运行的查询没有任何问题,那么它可以工作,如果我在Selenium IDE或Java Selenium测试中这样做,它将失败0.10秒。这就够了。