I have a set of web pages where I need to verify that a certain script is present. A have a lot of pages to verify so I would like to automate this part of testing. How can a create a sequence with selenium (or any other solution) where I have something of an array of webpages which is used for repetition of the same check through all these webpages? In other words, how can I cover a set of pages with one test? Because the check is the same for all of the pages.


Most programming languages support list of items and loops, some pseudo code:

  • Create a list of websites/urls to visit (e.g. array)
  • Start WebDriver
  • Foreach url in list (e.g. a loop to go over each item in the list)
    • Visit the page (e.g. driver.get(url))
    • Get the page source (e.g. driver.page_source)
    • Check the page source contains something unique to the script you are looking for (e.g. page_source.find("something unique"))
    • If script not found log url
  • It seems that selenium does not have the find() method for the String which getPageSource() method returns. Or am I missing something? – Seeker001 Feb 15 at 14:53
  • I suppose I can use contains(). – Seeker001 Feb 15 at 14:53
  • As you didn't provide the programming language you used I took Python examples, but other languages provider similar functions. Selenium does also not have a contains, the String getPageSource() probably has. – Niels van Reijmersdal Feb 15 at 15:24

If it's an externally downloaded script you can intercept the traffic and look for the file, it's easy with Puppeteer and less straightforward with other frameworks. See example here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.