1

谷歌搜索在此超时时只产生了源代码,我似乎无法通过查看 selenium 源代码的日志看到。我想知道是否有人遇到过这个硒问题

我们等待的条件如下

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
wait.until(ExpectedConditions.titleContains("Find a doctor"));

org.openqa.selenium.TimeoutException: Supplied function might have stalled
Build info: version: '4.0.0-alpha-5', revision: 'b3a0d621cc'
System info: host: 'localhost', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0', java.version: '11.0.6'
Driver info: driver.version: unknown
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:221)
    at com.orderlyhealth.scraper.json.CaredashHelper.getSearchResultsFromProviderImpl(CaredashHelper.java:320)
    at com.orderlyhealth.scraper.json.CaredashHelper.getSearchResultsFromProvider(CaredashHelper.java:294)
    at com.orderlyhealth.scraper.json.CaredashHelper.runImpl(CaredashHelper.java:65)
    at com.orderlyhealth.scraper.json.CaredashHelper.run(CaredashHelper.java:57)
    at com.orderlyhealth.scraper.json.JsonController.runBatchImpl(JsonController.java:200)
    at com.orderlyhealth.scraper.json.JsonController.executeBatch(JsonController.java:134)
    at com.orderlyhealth.scraper.json.JsonController.preRunBatchImpl(JsonController.java:110)
    at com.orderlyhealth.scraper.json.JsonController.runBatch(JsonController.java:86)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at org.webpieces.router.impl.services.ControllerInvoker.invokeController(ControllerInvoker.java:30)
    at org.webpieces.router.impl.services.SvcProxyForContent.invokeAndCoerce(SvcProxyForContent.java:56)
    at org.webpieces.router.impl.services.SvcProxyForContent.lambda$invokeMethod$1(SvcProxyForContent.java:49)
    at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(Unknown Source)
    at java.base/java.util.concurrent.CompletableFuture.thenCompose(Unknown Source)
    at org.webpieces.router.impl.services.SvcProxyForContent.invokeMethod(SvcProxyForContent.java:49)
    at org.webpieces.router.impl.services.SvcProxyForContent.lambda$invoke$0(SvcProxyForContent.java:33)
    at org.webpieces.util.futures.FutureHelper.syncToAsyncException(FutureHelper.java:169)
    at org.webpieces.router.impl.services.SvcProxyForContent.invoke(SvcProxyForContent.java:33)
    at org.webpieces.router.impl.services.SvcProxyForContent.invoke(SvcProxyForContent.java:19)
    at com.orderlyhealth.serverutil.filters.InternalSvcValidationFilter.filter(InternalSvcValidationFilter.java:33)
    at com.orderlyhealth.serverutil.filters.InternalSvcValidationFilter.filter(InternalSvcValidationFilter.java:13)
    at org.webpieces.router.impl.loader.ChainFilters$ServiceFilterProxy.invoke(ChainFilters.java:29)
    at org.webpieces.router.impl.loader.ChainFilters$ServiceFilterProxy.invoke(ChainFilters.java:17)
    at org.webpieces.plugin.json.JacksonCatchAllFilter.filter(JacksonCatchAllFilter.java:44)
    at org.webpieces.plugin.json.JacksonCatchAllFilter.filter(JacksonCatchAllFilter.java:28)
    at org.webpieces.router.impl.loader.ChainFilters$ServiceFilterProxy.invoke(ChainFilters.java:29)
    at org.webpieces.router.impl.loader.ChainFilters$ServiceFilterProxy.invoke(ChainFilters.java:17)
    at com.orderlyhealth.serverutil.filters.JobAndBatchIdFilter.filter(JobAndBatchIdFilter.java:33)
    at com.orderlyhealth.serverutil.filters.JobAndBatchIdFilter.filter(JobAndBatchIdFilter.java:13)
    at org.webpieces.router.impl.loader.ChainFilters$ServiceFilterProxy.invoke(ChainFilters.java:29)
    at org.webpieces.router.impl.loader.ChainFilters$ServiceFilterProxy.invoke(ChainFilters.java:17)
    at org.webpieces.router.impl.routers.Endpoint.invoke(Endpoint.java:27)
    at org.webpieces.router.impl.routeinvoker.ServiceInvoker.invokeService(ServiceInvoker.java:83)
    at org.webpieces.router.impl.routeinvoker.ServiceInvoker.lambda$invokeSvc$0(ServiceInvoker.java:67)
    at org.webpieces.util.futures.FutureHelper.syncToAsyncException(FutureHelper.java:169)
    at org.webpieces.util.futures.FutureHelper.catchBlock(FutureHelper.java:104)
    at org.webpieces.util.futures.FutureHelper.catchBlockWrap(FutureHelper.java:142)
    at org.webpieces.router.impl.routeinvoker.ServiceInvoker.invokeSvc(ServiceInvoker.java:66)
    at org.webpieces.router.impl.routebldr.RequestResponseStream.lambda$openStream$1(RequestResponseStream.java:57)
    at org.webpieces.router.impl.routeinvoker.RequestStreamWriter2.handleCompleteRequestImpl(RequestStreamWriter2.java:86)
    at org.webpieces.router.impl.routeinvoker.RequestStreamWriter2.processPiece(RequestStreamWriter2.java:68)
    at org.webpieces.router.impl.routers.NonStreamingWebAppErrorProxy.lambda$processPiece$0(NonStreamingWebAppErrorProxy.java:41)
    at org.webpieces.util.futures.FutureHelper.syncToAsyncException(FutureHelper.java:169)
    at org.webpieces.util.futures.FutureHelper.catchBlock(FutureHelper.java:104)
    at org.webpieces.router.impl.routers.NonStreamingWebAppErrorProxy.processPiece(NonStreamingWebAppErrorProxy.java:40)
    at org.webpieces.router.impl.TxStreamWriter.processPiece(TxStreamWriter.java:24)
    at org.webpieces.frontend2.impl.ProxyHttpStream$ProxyWriter.processPiece(ProxyHttpStream.java:161)
    at org.webpieces.frontend2.impl.Layer2Http11Handler.lambda$processPiece$7(Layer2Http11Handler.java:210)
    at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(Unknown Source)
    at java.base/java.util.concurrent.CompletableFuture.thenCompose(Unknown Source)
    at org.webpieces.frontend2.impl.Layer2Http11Handler.processPiece(Layer2Http11Handler.java:210)
    at org.webpieces.frontend2.impl.Layer2Http11Handler.lambda$null$4(Layer2Http11Handler.java:199)
    at org.webpieces.util.futures.FutureHelper.syncToAsyncException(FutureHelper.java:169)
    at org.webpieces.util.futures.FutureHelper.finallyBlock(FutureHelper.java:55)
    at org.webpieces.frontend2.impl.Layer2Http11Handler.lambda$processData$6(Layer2Http11Handler.java:198)
    at org.webpieces.util.locking.PermitQueue.processItemFromQueue(PermitQueue.java:82)
    at org.webpieces.util.locking.PermitQueue.runRequest(PermitQueue.java:62)
    at org.webpieces.frontend2.impl.Layer2Http11Handler.processData(Layer2Http11Handler.java:184)
    at org.webpieces.frontend2.impl.Layer2Http11Handler.processCorrectly(Layer2Http11Handler.java:173)
    at org.webpieces.frontend2.impl.Layer2Http11Handler.lambda$processWithBackpressure$3(Layer2Http11Handler.java:149)
    at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(Unknown Source)
    at java.base/java.util.concurrent.CompletableFuture.thenCompose(Unknown Source)
    at org.webpieces.frontend2.impl.Layer2Http11Handler.processWithBackpressure(Layer2Http11Handler.java:149)
    at org.webpieces.frontend2.impl.Layer2Http11Handler.initialDataImpl(Layer2Http11Handler.java:72)
    at org.webpieces.frontend2.impl.Layer2Http11Handler.initialData(Layer2Http11Handler.java:48)
    at org.webpieces.frontend2.impl.Layer1ServerListener.lambda$initialData$1(Layer1ServerListener.java:62)
    at org.webpieces.util.futures.FutureHelper.syncToAsyncException(FutureHelper.java:169)
    at org.webpieces.util.futures.FutureHelper.catchBlock(FutureHelper.java:104)
    at org.webpieces.util.futures.FutureHelper.catchBlockWrap(FutureHelper.java:142)
    at org.webpieces.frontend2.impl.Layer1ServerListener.initialData(Layer1ServerListener.java:61)
    at org.webpieces.frontend2.impl.Layer1ServerListener.incomingData(Layer1ServerListener.java:51)
    at org.webpieces.asyncserver.impl.ProxyDataListener.incomingData(ProxyDataListener.java:26)
    at org.webpieces.nio.impl.threading.ThreadDataListener$DataListeneRunanble.run(ThreadDataListener.java:54)
    at org.webpieces.util.threading.SessionExecutorImpl$RunnableWithKey.run(SessionExecutorImpl.java:121)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.util.concurrent.TimeoutException: null
    at java.base/java.util.concurrent.CompletableFuture.timedGet(Unknown Source)
    at java.base/java.util.concurrent.CompletableFuture.get(Unknown Source)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:209)
            ... 80 common frames omitted

任何想法如何解决这一问题?这在我们身上发生了很多。

4

3 回答 3

1

事实证明,当您中间有一个错误的代理时,我注意到浏览器会在页面上等待。这将导致硒驱动程序挂起。这是一个非常间歇性的问题,因此很难缩小到代理问题。

于 2020-06-26T14:26:15.390 回答
0

此错误消息...

org.openqa.selenium.TimeoutException: Supplied function might have stalled
Build info: version: '4.0.0-alpha-5', revision: 'b3a0d621cc'
System info: host: 'localhost', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0', java.version: '11.0.6'
Driver info: driver.version: unknown

...暗示TimeoutException在等待title包含 string时发生Find a doctor


分析

我认为ExpectedConditions 的定义没有任何重大变化,titleContains()其定义如下:

/**
 * An expectation for checking that the title contains a case-sensitive substring
 *
 * @param title the fragment of title expected
 * @return true when the title matches, false otherwise
 */
public static ExpectedCondition<Boolean> titleContains(final String title) {
  return new ExpectedCondition<Boolean>() {
    private String currentTitle = "";

    @Override
    public Boolean apply(WebDriver driver) {
      currentTitle = driver.getTitle();
      return currentTitle != null && currentTitle.contains(title);
    }

    @Override
    public String toString() {
      return String.format("title to contain \"%s\". Current title: \"%s\"", title, currentTitle);
    }
  };
}

但是TimeoutException似乎是由ExecutionException引起的,这看起来有点奇怪。

/**
 * Repeatedly applies this instance's input value to the given function until one of the following
 * occurs:
 * <ol>
 * <li>the function returns neither null nor false</li>
 * <li>the function throws an unignored exception</li>
 * <li>the timeout expires</li>
 * <li>the current thread is interrupted</li>
 * </ol>
 *
 * @param isTrue the parameter to pass to the {@link ExpectedCondition}
 * @param <V>    The function's expected return type.
 * @return The function's return value if the function returned something different
 * from null or false before the timeout expired.
 * @throws TimeoutException If the timeout expires.
 */
@Override
public <V> V until(Function<? super T, V> isTrue) {
  try {
    return CompletableFuture.supplyAsync(checkConditionInLoop(isTrue))
        .get(deriveSafeTimeout(), TimeUnit.MILLISECONDS);
  } catch (ExecutionException cause) {
    if (cause.getCause() instanceof RuntimeException) {
      throw (RuntimeException) cause.getCause();
    } else if (cause.getCause() instanceof Error) {
      throw (Error) cause.getCause();
    }

    throw new RuntimeException(cause);
  } catch (InterruptedException cause) {
    Thread.currentThread().interrupt();
    throw new RuntimeException(cause);
  } catch (java.util.concurrent.TimeoutException cause) {
    throw new TimeoutException("Supplied function might have stalled", cause);
  }
}

但是driver.version: unknown给我们一个提示,即您使用的二进制文件版本之间存在不兼容。

此外,在 Selenium 的下一个版本中,WebDriverWait的构造函数将被弃用。

@Deprecated
public WebDriverWait(WebDriver driver, long timeoutInSeconds) {
  this(driver, Duration.ofSeconds(timeoutInSeconds));
}

中使用的WebDriverWait的新构造函数(目前在Alpha中)是:

public WebDriverWait(WebDriver driver, Duration timeout) {
  this(
      driver,
      timeout,
      Duration.ofMillis(DEFAULT_SLEEP_TIMEOUT),
      Clock.systemDefaultZone(),
      Sleeper.SYSTEM_SLEEPER);
}

用法应该是:

new WebDriverWait(driver, Duration.ofSeconds(10));

爪哇 11

当您使用java.version: '11.0.6'时,Selenium仍然与Java 11不兼容。但是一旦Java 11发布并且Buck支持它,工具链将被重新调整以支持Java 11


解决方案

战略解决方案是安装最新版本的JDK 8u251并执行@Tests


参考

您可以在Unable to import org.openqa.selenium.WebDriver using Selenium and Java 11中找到相关的详细讨论

于 2020-06-24T20:39:30.190 回答
0

它说得很清楚,即 TimeoutException,更改超时,你给了 30 毫秒,但实际上需要更多……给它超过 30,它会顺利工作。

于 2021-11-29T16:32:35.047 回答