當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Page.%24x方法代碼示例

本文整理匯總了TypeScript中puppeteer.Page.%24x方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Page.%24x方法的具體用法?TypeScript Page.%24x怎麽用?TypeScript Page.%24x使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在puppeteer.Page的用法示例。


在下文中一共展示了Page.%24x方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: clickSwitchAccount

  public async clickSwitchAccount(page: Page): Promise<boolean> {
    log.verbose('PuppetPuppeteerBridge', 'clickSwitchAccount()')

    // https://github.com/GoogleChrome/puppeteer/issues/537#issuecomment-334918553
    // async function listXpath(thePage: Page, xpath: string): Promise<ElementHandle[]> {
    //   log.verbose('PuppetPuppeteerBridge', 'clickSwitchAccount() listXpath()')

    //   try {
    //     const nodeHandleList = await (thePage as any).evaluateHandle(xpathInner => {
    //       const nodeList: Node[] = []
    //       const query = document.evaluate(xpathInner, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
    //       for (let i = 0, length = query.snapshotLength; i < length; ++i) {
    //         nodeList.push(query.snapshotItem(i))
    //       }
    //       return nodeList
    //     }, xpath)
    //     const properties = await nodeHandleList.getProperties()

    //     const elementHandleList:  ElementHandle[] = []
    //     const releasePromises:    Promise<void>[] = []

    //     for (const property of properties.values()) {
    //       const element = property.asElement()
    //       if (element)
    //         elementHandleList.push(element)
    //       else
    //         releasePromises.push(property.dispose())
    //     }
    //     await Promise.all(releasePromises)
    //     return elementHandleList
    //   } catch (e) {
    //     log.verbose('PuppetPuppeteerBridge', 'clickSwitchAccount() listXpath() exception: %s', e)
    //     return []
    //   }
    // }

    // TODO: use page.$x() (with puppeteer v1.1 or above) to replace DIY version of listXpath() instead.
    // See: https://github.com/GoogleChrome/puppeteer/blob/v1.1.0/docs/api.md#pagexexpression

    const XPATH_SELECTOR = `//div[contains(@class,'association') and contains(@class,'show')]/a[@ng-click='qrcodeLogin()']`
    try {
      // const [button] = await listXpath(page, XPATH_SELECTOR)
      const [button] = await page.$x(XPATH_SELECTOR)
      if (button) {
        await button.click()
        log.silly('PuppetPuppeteerBridge', 'clickSwitchAccount() clicked!')
        return true

      } else {
        log.silly('PuppetPuppeteerBridge', 'clickSwitchAccount() button not found')
        return false
      }

    } catch (e) {
      log.silly('PuppetPuppeteerBridge', 'clickSwitchAccount() exception: %s', e)
      throw e
    }
  }
開發者ID:miggame,項目名稱:wechaty,代碼行數:58,代碼來源:bridge.ts


注:本文中的puppeteer.Page.%24x方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。