Background: I am trying to generate quotes from an internal website and then scrape the prices that are given. Since the prices can change depending on the product and other variables, I can't use nice locators like page.getByRole()
, for instance.
Problem: Instead, I'm trying to use CSS locators to unpack a deeply nested div. (Eventually the plan is to write a for-loop to do part of this so I can get each price in a row, but for now I want to just get the first price, which is the Product Subtotal.)
Request: I'd really appreciate any help with determining if my locator below makes sense, and suggestions for how to improve it.
This is my locator so far:
await page.locator("ul > .navbar-nav").locator("#dq-totals").locator('.total.d-flex.justify-content-end').locator('.d-flex.totals').locator('.container-fluid').nth(0).locator('.justify-content-between').locator('.col-12').innerText()
(I know it's gross)
Attached is the structure of the HTML as a screenshot, to compare my locator to.
Thanks for taking the time to read this question! ☺️ <:playwright:1054714813638516757>
This thread is trying to answer question "How can I improve my CSS locator to unpack a deeply nested div and scrape prices from an internal website?"
Remember the text and hasText locator arguments can be a regexp, so you could something like
page.getByRole("listitem").all()
To get each row, then for the colums:
youRowLocator.getByText(/\$/).all()
https://playwright.dev/docs/api/class-locator#locator-filter-option-has-text
Related Ask AI answer for "What information is needed to evaluate and improve a CSS locator for a deeply nested div in @playwright/test?".
I'm sorry, but without more specific details, I can't provide guidance on your CSS locator for a deeply nested div. Please provide more context or rephrase your question. This way, I can give you the best possible assistance.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].