Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat: treat selectors with leading '(//' as xpath (#821)
Andrey Lushnikovb82bc5fbd48a
diff --git a/src/dom.ts b/src/dom.tsindex 1efbe3e855..e27572f5e9 100644--- a/src/dom.ts+++ b/src/dom.ts@@ -511,7 +511,9 @@ function normalizeSelector(selector: string): string {const eqIndex = selector.indexOf('=');if (eqIndex !== -1 && selector.substring(0, eqIndex).trim().match(/^[a-zA-Z_0-9-]+$/))return selector;- if (selector.startsWith('//'))+ // If selector starts with '//' or '//' prefixed with multiple opening+ // parenthesis, consider xpath. @see https://github.com/microsoft/playwright/issues/817+ if (/^\(*\/\//.test(selector))return 'xpath=' + selector;if (selector.startsWith('"'))return 'text=' + selector;diff --git a/test/queryselector.spec.js b/test/queryselector.spec.jsindex 54c6e60712..38a3de150c 100644--- a/test/queryselector.spec.js+++ b/test/queryselector.spec.js@@ -177,6 +177,11 @@ module.exports.describe = function({testRunner, expect, selectors, FFOX, CHROMIUconst element = await page.$('//html/body/section');expect(element).toBeTruthy();});+ it('should auto-detect xpath selector with starting parenthesis', async({page, server}) => {+ await page.setContent('<section>test</section>');+ const element = await page.$('(//section)[1]');+ expect(element).toBeTruthy();+ });it('should auto-detect text selector', async({page, server}) => {await page.setContent('<section>test</section>');const element = await page.$('"test"');