Selenium FluentWait不忽略异常

Selenium FluentWait不忽略异常,selenium,junit,selenium-chromedriver,Selenium,Junit,Selenium Chromedriver,我有一些Selenium Chromedriver代码,它点击一个按钮,几秒钟后,一个项目出现在网页上,我需要捕获文本(基本上是一个成功/失败响应)。我可以看到按钮点击正在工作,但脚本在按下按钮后立即停止,出现异常。我可以验证按钮点击是否有效,因为脚本停止几秒钟后,要检查的元素出现在屏幕上 例外情况是 Caused by org.openqa.selenium.NoSuchElementException: no such element 这是有意义的,因为在发生此异常时,元素不在那里,并且在

我有一些Selenium Chromedriver代码,它点击一个按钮,几秒钟后,一个项目出现在网页上,我需要捕获文本(基本上是一个成功/失败响应)。我可以看到按钮点击正在工作,但脚本在按下按钮后立即停止,出现异常。我可以验证按钮点击是否有效,因为脚本停止几秒钟后,要检查的元素出现在屏幕上

例外情况是

Caused by org.openqa.selenium.NoSuchElementException: no such element
这是有意义的,因为在发生此异常时,元素不在那里,并且在几秒钟内不会在那里

异常来自此命令

myWaitVar.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@data-aura-class=\"forceActionsText\"]")));
myWaitVar定义为:

myWaitVar = new FluentWait<WebDriver>(driver)
  .withTimeout(Duration.ofSeconds(120))
  .pollingEvery(Duration.ofSeconds(10))
  .ignoring(org.openqa.selenium.NoSuchElementException.class);

我在其他绑定中也遇到过这个问题。最终只是解决了这个问题,很高兴看到一个真正的解决方案:)你们能用ExpectedConditionPresenceofAllelementsLocatedBy(最终由定位器)检查一下吗如果它不在这里发生,那么我们可以通过扩展预期的条件来编写变通方法,就像line一样culprit@Slimy43如果您熟悉Selenium.For调试此问题,请设置System.setProperty(“webdriver.chrome.verboseLogging”,“true”);对于Chrome驱动程序。FluentWait wait=new FluentWait(driver).pollingEvery(Duration.ofSeconds(2)).withTimeout(Duration.ofSeconds(10)).ignoreing(NoSuchElementException.class);等一下。至少应该有4个有效负载,带有[156705197.741][INFO]:[8e1b94fdc7f07def00e4cad2789379b9]命令FindElement{“使用”:“xpath”,在日志中。让我知道您看到了什么。非常感谢您的讨论,今天上午我可以尝试一些东西。关于定位器,是的,它是正确的。正如我在编辑中建议的,如果我将代码延迟到DOM包含元素的位置,一切正常。有趣的是,您说NoTouchElement被d忽略efault,我不知道这一点,你是对的。我也很想知道它是否来自其他地方。今天早上我将使用调试集重新运行测试。我在其他绑定中也遇到了这个问题。最终只是解决了这个问题,如果能看到一个真正的解决方案就好了:)你能检查ExpectedCondition presenceOfAl吗lElementsLocatedBy(final By locator)如果它不在这里发生,那么我们可以通过扩展预期的条件来编写变通方法,如line isculprit@Slimy43如果您对Selenium感到满意,为调试此问题,请为chrome驱动程序设置System.setProperty(“webdriver.chrome.verboseLogging”,“true”);FluentWait wait=new FluentWait(驱动程序).pollingEvery(Duration.ofSeconds(2)).withTimeout(Duration.ofSeconds(10)).ignoreing(NoSuchElementException.class);对于此等待。应至少有4个-Payload与[156705197.741][INFO]:[8e1b94fdc7f07def00e4cad2789379b9]命令FindElement{“using”:“xpath”,在日志中。让我知道您看到了什么。非常感谢您的讨论,今天上午我可以尝试一些东西。关于定位器,是的,它是正确的。正如我在编辑中建议的,如果我将代码延迟到DOM包含元素的位置,一切正常。有趣的是,您说NoTouchElement被d忽略efault,我不知道这一点,你是对的。我也很想知道它是否来自其他地方。今天早上我将使用调试集重新运行测试。
[1567065113.459][INFO]: [ebbf7271cafbc1f7e2dba437ac32b004] COMMAND FindElement {
   "using": "xpath",
   "value": "//*[@data-aura-class=\"forceActionsText\"]"
}
[1567065113.459][INFO]: Waiting for pending navigations...
[1567065113.459][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=246) CB6F87B5FC515B000A21C08C843E210B {
   "expression": "1"
}
[1567065113.464][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=246) CB6F87B5FC515B000A21C08C843E210B {
   "result": {
      "description": "1",
      "type": "number",
      "value": 1
   }
}
[1567065113.464][INFO]: Done waiting for pending navigations. Status: ok
[1567065113.467][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=247) CB6F87B5FC515B000A21C08C843E210B {
   "expression": "(function() { // Copyright (c) 2012 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\n/**\n * Enum f...",
   "returnByValue": true
}
[1567065113.481][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=247) CB6F87B5FC515B000A21C08C843E210B {
   "result": {
      "type": "object",
      "value": {
         "status": 0,
         "value": null
      }
   }
}
[1567065113.481][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=248) CB6F87B5FC515B000A21C08C843E210B {
   "expression": "1"
}
[1567065113.483][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=248) CB6F87B5FC515B000A21C08C843E210B {
   "result": {
      "description": "1",
      "type": "number",
      "value": 1
   }
}
[1567065113.483][INFO]: Waiting for pending navigations...
[1567065113.483][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=249) CB6F87B5FC515B000A21C08C843E210B {
   "expression": "1"
}
[1567065113.483][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=249) CB6F87B5FC515B000A21C08C843E210B {
   "result": {
      "description": "1",
      "type": "number",
      "value": 1
   }
}
[1567065113.483][INFO]: Done waiting for pending navigations. Status: ok
[1567065113.483][INFO]: [ebbf7271cafbc1f7e2dba437ac32b004] RESPONSE FindElement ERROR no such element: Unable to locate element: {"method":"xpath","selector":"//*[@data-aura-class="forceActionsText"]"}
  (Session info: chrome=76.0.3809.132)