提交 d466c152 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

puppeteer does not support XPath, its a Selector. use a patch (fix #636)

上级 161adf3d
......@@ -638,9 +638,35 @@ export class Bridge extends EventEmitter {
public async clickSwitchAccount(): Promise<boolean> {
log.verbose('PuppetWebBridge', 'clickSwitchAccount()')
const SELECTOR = `//div[contains(@class,'association') and contains(@class,'show')]/a[@ng-click='qrcodeLogin()']`
// https://github.com/GoogleChrome/puppeteer/issues/537#issuecomment-334918553
async function waitForXpath(page: Page, xpath: string) {
const resultsHandle = await (page as any).evaluateHandle(xpathInner => {
const results = [] as any
const query = document.evaluate(xpathInner, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (let i = 0, length = query.snapshotLength; i < length; ++i) {
results.push(query.snapshotItem(i));
}
return results;
}, xpath);
const properties = await resultsHandle.getProperties();
const result = [] as any
const releasePromises = [] as any
for (const property of properties.values()) {
const element = property.asElement();
if (element)
result.push(element);
else
releasePromises.push(property.dispose());
}
await Promise.all(releasePromises);
return result;
}
const XPATH_SELECTOR = `//div[contains(@class,'association') and contains(@class,'show')]/a[@ng-click='qrcodeLogin()']`
// const DOM_
try {
const button = await this.page.$(SELECTOR)
// const button = await this.page.$(XPATH_SELECTOR)
const [button] = await waitForXpath(this.page, XPATH_SELECTOR)
await button.click()
// const button = await this.driver.driver.findElement(By.xpath(
// "//div[contains(@class,'association') and contains(@class,'show')]/a[@ng-click='qrcodeLogin()']"))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册