I want to use Python/Webdriver to run through many client websites (and subpages within those websites) and take screenshots of each page. Currently, I have this working, but all clients are in their own files. Each client has the same subpages, so scaling and adding/removing can become tedious. I want to combine all the files into one file since they all use the same pages, but different base URL (per client). For example, myfirsturl.com and mysecondurl.com both have a /subpage1, /subpage2, /subpage3, etc. I figured using some sort of loop and/or nested loop was the best way to do this, but I can't figure this out. I am brand new to automation so I have a very beginner knowledge and mentality, so please be gentle :). After each step, I want to take a screenshot and save it for manual review/validation.

So, in English, it would be:

  1. Go to client1
  2. Take/save screenshot
  3. Go to client1/subpage1
  4. Take/save screenshot
  5. Go to client1/subpage2
  6. Take/save screenshot
  7. Go to client2
  8. Take/save screenshot
  9. Go to client2/subpage1
  10. Take/save screenshot

and so on....

Then, after that is done in, say, Firefox, do it again in Chrome.

Any ideas?

Edit: I know how to take screenshots. My question is how can I do the above sequence with loops, taking a screenshot of each page.

  • 1
    Did you tried using google? In 5 seconds I found get_screenshot_as_file() method. See API docs and FAQ – Peter M. - stands for Monica Feb 13 '15 at 14:52
  • Yes, I have that already. My question is how can I combine all of the separate files I have into one file and use some loops to do all the work of going to page X, then the subpages of that, capturing a screenshot of each. My question was not how to actually capture a screenshot. – python Feb 13 '15 at 18:14
  • Rest is plain old programming and image processing. – Peter M. - stands for Monica Feb 13 '15 at 18:22
  • Which is what I need the help with. As stated in my original question, I am brand new to automation so I have a very beginner knowledge and mentality. I'm trying to learn. I have everything working fine when each client is in its own file, so I'm not looking for handouts. I have that learning experience. However, I am having trouble creating one file where everything is done in that one file without any/a lot of code repetition (keeping an eye on scaling in the future). This is where I need help...in the logic and programming of getting it into one file. The way I have it now won't scale well. – python Feb 13 '15 at 18:27
  • 2
    I'm voting to close this question as off-topic because it is about how to use loops in a programming language and not about testing per-se. – user246 Feb 13 '15 at 20:05

Sure it's a low level question, but based on how I understand the question this would be my suggestion. I was a beginner once too and I remember how frustrating it can be.

# make a list for everything you want to loop over
browsers = [

client_urls = [

sub_pages = [

#create a list of all clients and pages
complete_urls = [client_url + sub_page for client_url in client_urls for sub_page in sub_pages] 

#check that list in each browser
for browser in browsers:
    #insert your code for creating a new webdriver for the given browser
    for complete_url in complete_urls:
| improve this answer | |

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