Nightmare conditional wait()

后端 未结 3 1514
执笔经年
执笔经年 2020-12-20 05:24

I\'m trying to crawl a webpage using Nightmare, but want to wait for #someelem to be present, only if it actually exists. Otherwise, I want Nightmare to move on

3条回答
  •  旧时难觅i
    2020-12-20 06:10

    1. As mentioned in documentation of nightmarejs,

    .wait(selector) Wait until the element selector is present e.g. .wait('#pay-button')

    the wait wait works in this case only till the element first becomes visible if it does not then it will work till default timeout of 30s

    1. wait with function

      .wait(function () { return (document.querySelector(selector) === null); })

    where selector is the element based on whose existence in the DOM we wait.

提交回复
热议问题