本文整理汇总了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
}
}