Automated Testing Elements on a Lazy Load Page with Selenium WebDriver

How to verify elements that get dynamically loaded on a page using Selenium WebDriver

driver.get("https://agileway.substack.com/archive")
driver.find_element(:link_text, "12 Payment Test (AJAX)").click
try_for(4) { expect(page_text).to include("Selenium Explicit Waits") }
driver.get("https://agileway.substack.com/archive")
driver.find_element(:link_text, "Fake End-to-End Test Automation Clarified").click
driver.find_element(:tag_name, "body").send_keys(:page_down)
100.times do |x|
puts("Scroll: #{x + 1}")
driver.find_element(:tag_name, "body").send_keys(:page_down)
sleep 1
begin
driver.find_element(:link_text, "Fake End-to-End Test Automation Clarified").click
# quit the loop if found
break
rescue => e
# not found, continue
end
end
expect(page_text).to include("After knowing what is not real, motivated professionals can learn and achieve the real.")
100.times do |x|
puts("Scroll: #{x + 1}")

# scroll to the visibility-check element at the bottom of the page
elem = driver.find_element(:class, "visibility-check")
driver.action.move_to(elem).perform
sleep 1

begin
driver.find_element(:link_text, "Fake End-to-End Test Automation Clarified").click
break
rescue => e
# not found, continue
end
end

sleep 3
expect(page_text).to include("After knowing what is not real, motivated professionals can learn and achieve the real.")

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store