Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(playwright): add functionality to fetch paginated content #2780

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dnwjn
Copy link

@dnwjn dnwjn commented Nov 14, 2024

Hi there!

First of all: thank you for creating this great piece of software, I've been running ChangeDetection smoothly and it's helped me greatly so far!

I ran into the issue where I had to keep track of a store page with pagination. As I couldn't find an option for paginated results in the program yet, I started tinkering around and I came to an implementation! I wanted to propose it, with the hope it would be a useful addition to your program!

Explanation

My code adds a checkbox underneath the Execute JavaScript before change detection field. When checked, 2 other fields become visible:

image

If this checkbox is checked, and if the pagination fields have been filled in, it will process the target page in Playwright, but it will target each page in the pagination until it reaches the last page. When it does so it will inject a hidden input into the page, with the extracted content as value, which can then be retrieved inside the filter. For example, this is my setup:

Execute JavaScript before change detection
() => {
  const xPathRes = document.evaluate('//div[@id="sd-cmp"]//button[span="Do not accept"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  xPathRes.singleNodeValue.click();
}
(Paginated) Execute JavaScript on each page
() => Array.from(document.querySelectorAll('.property > a')).map(el => el.href).toString();
(Paginated) Next page button selector
//li[@class='next']/a
CSS/JSONPath/JQ/XPath Filters
xpath:tokenize(//input[@id="cd_data"]/@value, ',')

Please let me know if you need me to explain or improve something. I hope it can be a valuable contribution to your project!

@dgtlmoon
Copy link
Owner

interesting, could you add a test? see the existing tests

@dgtlmoon
Copy link
Owner

I think generally the config would be too hard/obscure for 99% of people that use the app tho, bu thmmm

@dnwjn
Copy link
Author

dnwjn commented Nov 15, 2024

@dgtlmoon I will add tests asap! I wanted your point of view first before doing that, same as for documentation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants