Skip to content

[BUG] codegen producing weird selectors #6168

Closed

Description

Context:

  • Playwright Version: Version 1.10.0
  • Operating System: Mac
  • Node.js version: v15.13.0
  • Browser: Chromium, at least

System:
OS: macOS 11.2.3
Memory: 1.36 GB / 16.00 GB
Binaries:
Node: 15.13.0 - /usr/local/bin/node
npm: 7.7.6 - /usr/local/bin/npm
Languages:
Bash: 3.2.57 - /bin/bash

Code Snippet

Help us help you! Put down a short code snippet that illustrates your bug and
that we can run and debug locally. For example:

const { chromium } = require('playwright');
(async () => {
  const browser = await chromium.launch({
    headless: false
  });
  const context = await browser.newContext({
    locale: 'en-GB'
  });
  // Open new page
  const page = await context.newPage();
  // Go to https://xxx.my.salesforce.com/
  await page.goto('https://xxx.my.salesforce.com/');
  // Fill input[name="username"]
  await page.fill('input[name="username"]', 'USERNAME_HERE');
  // Press Tab
  await page.press('input[name="username"]', 'Tab');
  // Fill input[name="pw"]
  await page.fill('input[name="pw"]', 'PASSWORD_HERE');
  // Press Enter
  await page.press('input[name="pw"]', 'Enter');
  // Go to https://businez.lightning.force.com/one/one.app
  await page.goto('https://businez.lightning.force.com/one/one.app');
  // Go to https://businez.lightning.force.com/lightning/page/home
  await page.goto('https://businez.lightning.force.com/lightning/page/home');
  // Click text=Switch to Salesforce Classic
  await page.click('text=Switch to Salesforce Classic');
**// AT THIS POINT, I CLICKED ONE OF THE TABS. INSTEAD GRABBING THE TEXT, PLAYWRIGHT USED A GOTO**
  // assert.equal(page.url(), 'https://businez.my.salesforce.com/home/home.jsp?source=lex');
  // Go to https://businez.my.salesforce.com/003/o
  await page.goto('https://businez.my.salesforce.com/003/o');
**// CLICKING IN A DIFFERENT TAB PRODUCES THE EXPECTED SELECTOR...**
  // Click text=Accounts
  await page.click('text=Accounts');
  // assert.equal(page.url(), 'https://businez.my.salesforce.com/001/o');
**// NEXT: MORE WEIRD SELECTORS**
  // Click text=Setup
  await page.click('text=Setup');
  // assert.equal(page.url(), 'https://businez.my.salesforce.com/setup/forcecomHomepage.apexp?setupid=ForceCom&retURL=%2F001%2Fo');
  // Click img[alt="Expand - Manage Users - Level 1"]
  await page.click('img[alt="Expand - Manage Users - Level 1"]');
  // Click text=Permission Sets
  await page.click('text=Permission Sets');
  // assert.equal(page.url(), 'https://businez.my.salesforce.com/0PS?setupid=PermSets&retURL=%2Fui%2Fsetup%2FSetup%3Fsetupid%3DUsers');
  // Click text=Clone
  await page.click('text=Clone');
  // assert.equal(page.url(), 'https://businez.my.salesforce.com/udd/PermissionSet/newPermissionSet.apexp?retURL=%2F0PS%3Ffcf%3D00B5e000001j4oK%26rolodexIndex%3D-1%26page%3D1&id=0PS5e000000wrye&setupid=PermSets');
  // Go to https://businez.my.salesforce.com/0PS?setupid=PermSets&retURL=%2Fui%2Fsetup%2FSetup%3Fsetupid%3DUsers
  await page.goto('https://businez.my.salesforce.com/0PS?setupid=PermSets&retURL=%2Fui%2Fsetup%2FSetup%3Fsetupid%3DUsers');
  // Click text=On this page you can create, view, and manage permission sets. In addition, you
  await page.click('text=On this page you can create, view, and manage permission sets. In addition, you ');
**// THIS IS THE EXPECTED SELECTOR, OR A SIMILAR ONE, WHEN CLICKING 'CLONE' LINKS**
  // Click text=Clone
  await page.click('text=Clone');
  // assert.equal(page.url(), 'https://businez.my.salesforce.com/udd/PermissionSet/newPermissionSet.apexp?retURL=%2F0PS%3Ffcf%3D00B5e000001j4oK%26rolodexIndex%3D-1%26page%3D1&id=0PS5e000000wrye&setupid=PermSets');
  // Go to https://businez.my.salesforce.com/0PS?setupid=PermSets&retURL=%2Fui%2Fsetup%2FSetup%3Fsetupid%3DUsers
  await page.goto('https://businez.my.salesforce.com/0PS?setupid=PermSets&retURL=%2Fui%2Fsetup%2FSetup%3Fsetupid%3DUsers');
**// THESE ARE THE SELECTORS GENERATED FOR THE OTHER 'CLONE' LINKS**
  // Click #ext-gen11 div:has-text("0PS5e000000wrydCloneSalesforce Console UserEnable Salesforce Console UserSales C")
  await page.click('#ext-gen11 div:has-text("0PS5e000000wrydCloneSalesforce Console UserEnable Salesforce Console UserSales C")');
  // Click #ext-gen11 div:has-text("0PS5e000000wrydCloneSalesforce Console UserEnable Salesforce Console UserSales C")
  await page.click('#ext-gen11 div:has-text("0PS5e000000wrydCloneSalesforce Console UserEnable Salesforce Console UserSales C")');
  // Click #ext-gen11 div:has-text("0PS5e000000wrycCloneSalesforce CMS Integration AdminGives the admin data access ")
  await page.click('#ext-gen11 div:has-text("0PS5e000000wrycCloneSalesforce CMS Integration AdminGives the admin data access ")');
  // Click #ext-gen11 div:has-text("0PS5e0000001sXqCloneStandard Einstein Activity CaptureAccess to Standard Einstei")
  await page.click('#ext-gen11 div:has-text("0PS5e0000001sXqCloneStandard Einstein Activity CaptureAccess to Standard Einstei")');
  // ---------------------
  await context.close();
  await browser.close();
})();

Describe the bug

Hi, thanks for all the work you do on this project - its awesome

I'm finding different problems when generating selectors in the app above in different cases:

  1. The case with the tabs commented in the code above - it's like when the page it's initially loaded, playwright behaves different. After clicking a second tab, the selectors produced where the expected, i.e. using the 'Text' engine
  2. The different behaviors when clicking the different 'Clone' links under the 'Setup' page. I expected different selectors, since there are several links with that text, but not the shown above
  3. Finally, sometimes I click a simple link with a clear text, like 'Setup', and instead of getting a nice Text selector, I got a page.goto()
  • Adding the pw:api logs:

    pw:api waiting for selector "text=Switch to Salesforce Classic" +2s
    pw:api selector resolved to visible <a title="" dir="ltr" data-interactive-lib-uid="4" …>Switch to Salesforce Classic +26ms
    pw:api attempting click action +7ms
    pw:api waiting for element to be visible, enabled and stable +0ms
    pw:api element is visible, enabled and stable +42ms
    pw:api scrolling into view if needed +1ms
    pw:api done scrolling +2ms
    pw:api checking that element receives pointer events at (991.98,75.48) +3ms
    pw:api element does receive pointer events +9ms
    pw:api performing click action +1ms
    pw:api click action done +18ms
    pw:api waiting for scheduled navigations to finish +0ms
    pw:api navigated to "about:blank" +470ms
    pw:api "domcontentloaded" event fired +2ms
    pw:api navigated to "https://businez.my.salesforce.com/home/home.jsp?source=lex" +197ms
    pw:api navigated to "https://businez.my.salesforce.com/home/home.jsp?source=lex" +1ms
    pw:api navigations have finished +2ms
    pw:api navigated to "https://businez.my.salesforce.com/img/s.gif" +1s
    pw:api "domcontentloaded" event fired +483ms
    pw:api navigated to "about:blank" +135ms
    pw:api "domcontentloaded" event fired +2ms
    pw:api navigated to "https://login.salesforce.com/login/sessionserver212.html" +12ms
    pw:api "domcontentloaded" event fired +14ms
    pw:api navigated to "about:blank" +117ms
    pw:api "domcontentloaded" event fired +2ms
    pw:api "load" event fired +8ms
    pw:api navigated to "chrome-error://chromewebdata/" +511ms
    pw:api "domcontentloaded" event fired +30ms
    pw:api "load" event fired +1ms
    pw:api navigated to "about:blank" +158ms
    pw:api "load" event fired +2ms
    pw:api "domcontentloaded" event fired +0ms
    pw:api navigated to "https://businez.my.salesforce.com/home/home.jsp?source=lex" +26ms
    pw:api "networkidle" event fired +1s
    pw:api navigated to "https://businez.my.salesforce.com/003/o" +21s
    pw:api "domcontentloaded" event fired +289ms
    pw:api navigated to "about:blank" +24ms
    pw:api "domcontentloaded" event fired +3ms
    pw:api navigated to "https://login.salesforce.com/login/sessionserver212.html" +16ms
    pw:api "domcontentloaded" event fired +7ms
    pw:api "load" event fired +123ms
    pw:api "networkidle" event fired +614ms
    pw:api waiting for selector "text=Accounts" +9s
    pw:api selector resolved to visible Accounts +15ms
    pw:api attempting click action +3ms
    pw:api waiting for element to be visible, enabled and stable +0ms
    pw:api element is visible, enabled and stable +36ms
    pw:api scrolling into view if needed +0ms
    pw:api done scrolling +0ms
    pw:api checking that element receives pointer events at (186.26,96.48) +2ms
    pw:api element does receive pointer events +3ms
    pw:api performing click action +0ms
    pw:api click action done +19ms
    pw:api waiting for scheduled navigations to finish +0ms
    pw:api navigated to "https://businez.my.salesforce.com/001/o" +237ms
    pw:api navigated to "https://businez.my.salesforce.com/001/o" +0ms
    pw:api navigations have finished +2ms
    pw:api "domcontentloaded" event fired +206ms
    pw:api navigated to "about:blank" +10ms
    pw:api "domcontentloaded" event fired +2ms
    pw:api navigated to "https://login.salesforce.com/login/sessionserver212.html" +10ms
    pw:api "domcontentloaded" event fired +4ms
    pw:api "load" event fired +12ms
    pw:api "networkidle" event fired +505ms
    pw:api waiting for selector "text=Setup" +2s
    pw:api selector resolved to visible <a title="Setup" id="setupLink" href="/setup/forcec…>Setup +11ms
    pw:api attempting click action +2ms
    pw:api waiting for element to be visible, enabled and stable +0ms
    pw:api element is visible, enabled and stable +17ms
    pw:api scrolling into view if needed +0ms
    pw:api done scrolling +1ms
    pw:api checking that element receives pointer events at (977.81,44) +0ms
    pw:api element does receive pointer events +3ms
    pw:api performing click action +0ms
    pw:api click action done +8ms
    pw:api waiting for scheduled navigations to finish +0ms
    pw:api navigated to "https://businez.my.salesforce.com/setup/forcecomHomepage.apexp?setupid=ForceCom&retURL=%2F001%2Fo" +352ms
    pw:api navigated to "https://businez.my.salesforce.com/setup/forcecomHomepage.apexp?setupid=ForceCom&retURL=%2F001%2Fo" +0ms
    pw:api navigations have finished +2ms
    pw:api navigated to "about:blank" +2s
    pw:api navigated to "https://businez.my.salesforce.com/setup/forcecomHomepage.apexp?setupid=ForceCom&retURL=%2F001%2Fo" +2ms
    pw:api navigated to "about:blank" +5ms
    pw:api navigated to "https://businez.my.salesforce.com/setup/forcecomHomepage.apexp?setupid=ForceCom&retURL=%2F001%2Fo" +2ms
    pw:api navigated to "about:blank" +5ms
    pw:api navigated to "https://businez.my.salesforce.com/setup/forcecomHomepage.apexp?setupid=ForceCom&retURL=%2F001%2Fo" +2ms
    pw:api "domcontentloaded" event fired +20ms
    pw:api navigated to "about:blank" +10ms
    pw:api "domcontentloaded" event fired +1ms
    pw:api navigated to "https://login.salesforce.com/login/sessionserver212.html" +15ms
    pw:api "domcontentloaded" event fired +24ms
    pw:api navigated to "https://www.developerforce.com/ootbe/" +101ms
    pw:api "domcontentloaded" event fired +21ms
    pw:api navigated to "https://appexchange.salesforce.com/setupModule" +225ms
    pw:api navigated to "https://trailblazer.salesforce.com/communitySetupModule" +330ms
    pw:api "domcontentloaded" event fired +427ms
    pw:api "load" event fired +677ms
    pw:api "networkidle" event fired +496ms
    pw:api waiting for selector "img[alt="Expand - Manage Users - Level 1"]" +2s
    pw:api selector resolved to visible <img width="11" height="11" class="setupImage" alt="E…/> +10ms
    pw:api attempting click action +1ms
    pw:api waiting for element to be visible, enabled and stable +0ms
    pw:api element is visible, enabled and stable +4ms
    pw:api scrolling into view if needed +0ms
    pw:api done scrolling +1ms
    pw:api checking that element receives pointer events at (25.48,464.48) +0ms
    pw:api element does receive pointer events +3ms
    pw:api performing click action +0ms
    pw:api click action done +6ms
    pw:api waiting for scheduled navigations to finish +0ms
    pw:api navigations have finished +2ms
    pw:api waiting for selector "text=Permission Sets" +3s
    pw:api selector resolved to visible <a id="PermSets_font" href="/0PS?setupid=PermSets&r…>Permission Sets +16ms
    pw:api attempting click action +1ms
    pw:api waiting for element to be visible, enabled and stable +0ms
    pw:api element is visible, enabled and stable +5ms
    pw:api scrolling into view if needed +0ms
    pw:api done scrolling +1ms
    pw:api checking that element receives pointer events at (98.31,546) +1ms
    pw:api element does receive pointer events +3ms
    pw:api performing click action +0ms
    pw:api click action done +38ms
    pw:api waiting for scheduled navigations to finish +0ms
    pw:api navigated to "https://businez.my.salesforce.com/0PS?setupid=PermSets&retURL=%2Fui%2Fsetup%2FSetup%3Fsetupid%3DUsers" +409ms
    pw:api navigated to "https://businez.my.salesforce.com/0PS?setupid=PermSets&retURL=%2Fui%2Fsetup%2FSetup%3Fsetupid%3DUsers" +0ms
    pw:api navigations have finished +2ms
    pw:api navigated to "about:blank" +842ms
    pw:api "domcontentloaded" event fired +13ms
    pw:api navigated to "https://login.salesforce.com/login/sessionserver212.html" +52ms
    pw:api "domcontentloaded" event fired +8ms
    pw:api "load" event fired +91ms
    pw:api "networkidle" event fired +684ms
    pw:api waiting for selector "text=Clone" +5s
    pw:api selector resolved to visible Clone +25ms
    pw:api attempting click action +4ms
    pw:api waiting for element to be visible, enabled and stable +0ms
    pw:api element is visible, enabled and stable +34ms
    pw:api scrolling into view if needed +0ms
    pw:api done scrolling +0ms
    pw:api checking that element receives pointer events at (282.67,285) +1ms
    pw:api element does receive pointer events +3ms
    pw:api performing click action +0ms
    pw:api click action done +29ms
    pw:api waiting for scheduled navigations to finish +0ms
    pw:api navigated to "https://businez.my.salesforce.com/udd/PermissionSet/newPermissionSet.apexp?retURL=%2F0PS%3Ffcf%3D00B5e000001j4oK%26rolodexIndex%3D-1%26page%3D1&id=0PS5e000000wrye&setupid=PermSets" +486ms
    pw:api navigated to "https://businez.my.salesforce.com/udd/PermissionSet/newPermissionSet.apexp?retURL=%2F0PS%3Ffcf%3D00B5e000001j4oK%26rolodexIndex%3D-1%26page%3D1&id=0PS5e000000wrye&setupid=PermSets" +0ms
    pw:api navigations have finished +2ms
    pw:api navigated to "about:blank" +270ms
    pw:api "domcontentloaded" event fired +9ms
    pw:api navigated to "https://login.salesforce.com/login/sessionserver212.html" +6ms
    pw:api "domcontentloaded" event fired +5ms
    pw:api "load" event fired +106ms
    pw:api "networkidle" event fired +503ms
    pw:api navigated to "https://businez.my.salesforce.com/0PS?setupid=PermSets&retURL=%2Fui%2Fsetup%2FSetup%3Fsetupid%3DUsers" +95ms
    pw:api navigated to "about:blank" +219ms
    pw:api "domcontentloaded" event fired +11ms
    pw:api navigated to "https://login.salesforce.com/login/sessionserver212.html" +8ms
    pw:api "domcontentloaded" event fired +2ms
    pw:api "load" event fired +46ms
    pw:api "networkidle" event fired +531ms
    pw:api waiting for selector "text=On this page you can create, view, and manage permission sets. In addition, you " +19s
    pw:api selector resolved to visible

    +28ms
    pw:api attempting click action +3ms
    pw:api waiting for element to be visible, enabled and stable +0ms
    pw:api element is visible, enabled and stable +27ms
    pw:api scrolling into view if needed +1ms
    pw:api done scrolling +0ms
    pw:api checking that element receives pointer events at (742.48,136.47) +1ms
    pw:api element does receive pointer events +3ms
    pw:api performing click action +0ms
    pw:api click action done +7ms
    pw:api waiting for scheduled navigations to finish +0ms
    pw:api navigations have finished +0ms
    pw:api waiting for selector "text=Clone" +25s
    pw:api selector resolved to visible Clone +16ms
    pw:api attempting click action +2ms
    pw:api waiting for element to be visible, enabled and stable +0ms
    pw:api element is visible, enabled and stable +40ms
    pw:api scrolling into view if needed +0ms
    pw:api done scrolling +1ms
    pw:api checking that element receives pointer events at (282.67,285) +1ms
    pw:api element does receive pointer events +3ms
    pw:api performing click action +0ms
    pw:api click action done +22ms
    pw:api waiting for scheduled navigations to finish +0ms
    pw:api navigated to "https://businez.my.salesforce.com/udd/PermissionSet/newPermissionSet.apexp?retURL=%2F0PS%3Ffcf%3D00B5e000001j4oK%26rolodexIndex%3D-1%26page%3D1&id=0PS5e000000wrye&setupid=PermSets" +422ms
    pw:api navigated to "https://businez.my.salesforce.com/udd/PermissionSet/newPermissionSet.apexp?retURL=%2F0PS%3Ffcf%3D00B5e000001j4oK%26rolodexIndex%3D-1%26page%3D1&id=0PS5e000000wrye&setupid=PermSets" +1ms
    pw:api navigations have finished +1ms
    pw:api navigated to "about:blank" +201ms
    pw:api "domcontentloaded" event fired +11ms
    pw:api navigated to "https://login.salesforce.com/login/sessionserver212.html" +4ms
    pw:api "domcontentloaded" event fired +7ms
    pw:api "load" event fired +5ms
    pw:api "networkidle" event fired +500ms
    pw:api navigated to "https://businez.my.salesforce.com/0PS?setupid=PermSets&retURL=%2Fui%2Fsetup%2FSetup%3Fsetupid%3DUsers" +5s
    pw:api navigated to "about:blank" +251ms
    pw:api "domcontentloaded" event fired +8ms
    pw:api navigated to "https://login.salesforce.com/login/sessionserver212.html" +14ms
    pw:api "domcontentloaded" event fired +11ms
    pw:api "load" event fired +51ms
    pw:api "networkidle" event fired +526ms
    pw:api waiting for selector "#ext-gen11 div:has-text("0PS5e000000wrydCloneSalesforce Console UserEnable Salesforce Console UserSales C")" +4s
    pw:api selector resolved to visible
    +28ms
    pw:api attempting click action +3ms
    pw:api waiting for element to be visible, enabled and stable +0ms
    pw:api element is visible, enabled and stable +28ms
    pw:api scrolling into view if needed +0ms
    pw:api done scrolling +1ms
    pw:api checking that element receives pointer events at (734,351) +1ms
    pw:api element does receive pointer events +3ms
    pw:api performing click action +0ms
    pw:api click action done +54ms
    pw:api waiting for scheduled navigations to finish +0ms
    pw:api navigations have finished +3ms
    pw:api waiting for selector "#ext-gen11 div:has-text("0PS5e000000wrydCloneSalesforce Console UserEnable Salesforce Console UserSales C")" +23s
    pw:api selector resolved to visible
    +20ms
    pw:api attempting click action +3ms
    pw:api waiting for element to be visible, enabled and stable +0ms
    pw:api element is visible, enabled and stable +15ms
    pw:api scrolling into view if needed +0ms
    pw:api done scrolling +1ms
    pw:api checking that element receives pointer events at (734,351) +1ms
    pw:api element does receive pointer events +4ms
    pw:api performing click action +0ms
    pw:api click action done +21ms
    pw:api waiting for scheduled navigations to finish +0ms
    pw:api navigations have finished +2ms
    pw:api waiting for selector "#ext-gen11 div:has-text("0PS5e000000wrycCloneSalesforce CMS Integration AdminGives the admin data access ")" +3s
    pw:api selector resolved to visible
    +19ms
    pw:api attempting click action +2ms
    pw:api waiting for element to be visible, enabled and stable +0ms
    pw:api element is visible, enabled and stable +5ms
    pw:api scrolling into view if needed +0ms
    pw:api done scrolling +1ms
    pw:api checking that element receives pointer events at (734,329) +1ms
    pw:api element does receive pointer events +2ms
    pw:api performing click action +1ms
    pw:api click action done +53ms
    pw:api waiting for scheduled navigations to finish +0ms
    pw:api navigations have finished +2ms
    pw:api waiting for selector "#ext-gen11 div:has-text("0PS5e0000001sXqCloneStandard Einstein Activity CaptureAccess to Standard Einstei")" +8s
    pw:api selector resolved to visible <div class="x-grid3-row x-grid3-row-last x-grid3-row-…>… +18ms
    pw:api attempting click action +2ms
    pw:api waiting for element to be visible, enabled and stable +0ms
    pw:api element is visible, enabled and stable +10ms
    pw:api scrolling into view if needed +0ms
    pw:api done scrolling +0ms
    pw:api checking that element receives pointer events at (734,373) +1ms
    pw:api element does receive pointer events +3ms
    pw:api performing click action +0ms
    pw:api click action done +58ms
    pw:api waiting for scheduled navigations to finish +0ms
    pw:api navigations have finished +3ms

Again, thank you for the awesome project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions