GithubHelp home page GithubHelp logo

Comments (4)

lmlikota avatar lmlikota commented on July 24, 2024

You can click on that element (purple circle on screenshot) using Xpath //div[@class='p-datatable-wrapper']/table/tbody/tr[1]/td[10]/a[@class="edit css-1hqfesk"] You can join Playwright Slack channel if you like playwright.slack.com.

from demo.playwright.

MarcusFelling avatar MarcusFelling commented on July 24, 2024

@lmlikota XPath can be fragile, and the css class will likely be dynamic and change in this case, so it should be avoided as selector.

@ramnutheti Are you looking to validate the table data? For that, you would query the page with specific selectors for the table, then assert its contents.
e.g.
await expect(page.locator('.my-table-row').nth(3)).toContainText('Job');

You can also use locators to work with element lists: https://playwright.dev/docs/locators#lists

from demo.playwright.

lmlikota avatar lmlikota commented on July 24, 2024

@MarcusFelling Are you suggesting not to use Xpath and CSS selectors? But in your above example you have used .mytable row which is CSS class, nth(3) which is index and toContainText which is also something that CSS doesn't support out of the box but Xpath does .

So above example is combination of CSS selector using Class, index and partial text is not tied to DOM changes? How come if it relies on CSS class, row index and partial text? If any of them change in DOM this locator will fail. I'm trying to understand how is this better then writing relative Xpath.

So in Xpath your above example would be:
await expect(page.locator('//*[@class='my-table-row'])[3]/*[contains(.,"Job")]')

from demo.playwright.

MarcusFelling avatar MarcusFelling commented on July 24, 2024

https://playwright.dev/docs/selectors#best-practices

from demo.playwright.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.