1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-01-06 03:03:57 +02:00

Added example of handling lazy loading lists

This commit is contained in:
Tim Voronov 2021-09-20 01:59:50 -04:00
parent 2f399c669e
commit 0c4a18cb76
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,5 @@
query:
ref: ../../../examples/lazy-loading.fql
assert:
text: RETURN T::LEN(@lab.data.query.result, 50)

29
examples/lazy-loading.fql Normal file
View File

@ -0,0 +1,29 @@
LET doc = DOCUMENT('https://soundcloud.com/charts/top', { driver: "cdp" })
LET endSelector = ''
LET listSelector = '.chartTracks ul'
WAIT_ELEMENT(doc, listSelector)
LET list = ELEMENT(doc, listSelector)
LET initialCount = ELEMENTS_COUNT(list, 'li')
LET lastItem = 50
LET preload = (
FOR i DO WHILE !ELEMENT_EXISTS(doc, '.chartTracksEnd')
LET initial = i > 0 ? SCROLL_BOTTOM(doc) && WAIT(500) && SCROLL_TOP(doc) && false : true
RETURN NONE
)
WAIT_ELEMENT(list, FMT('li:nth-child({})', lastItem))
FOR track, i IN ELEMENTS(list, 'li')
RETURN {
num: i + 1,
artist: TRIM(INNER_TEXT(track, '.chartTrack__details .chartTrack__username')),
track: TRIM(INNER_TEXT(track, '.chartTrack__details .chartTrack__title'))
}