Selenium Screenshots

Tobi Olabode
2 min readDec 16, 2018

--

In a recent project, I had the task to take screenshots of websites using the automation tool selenium. To do this I had to do the normal set up of starting the webdriver of your browser your choice. im using firefox so my code reads as driver = webdriver.Firefox(). Next, we can navigate to the website you want. My chosen website was Bloomberg Europe as I want a website with clear sections I can navigate to. But this is the point I got stuck as when you log in to a website in Europe you are greeted with a prompt ask your permission to use your personal data. This is because of GDPR. I thought it will be an easy solution as I will just get the element containing the accept button then move on. So first I just copied the Xpath of the element saved a variable I called GDPR button to driver.find_element_by_xpath() but the script was repeatedly saying the XPath cant be found. So decided to use the class name instead but did not work. So I decided to move on and code up the rest of the code as I could not think of the solution. The screenshot code did not take that much-thinking power as did the GDPR prompt. I first used the command find_elements_by_class_name and used the section headline element in the parenthesis. The next line was driver.save_screenshot(‘sample_screenshot_1.png’) which directs selenium to take a screenshot and the next line was a simple print command saying “Screen saved” for a good may of tracking if the program successfully took a screenshot. The next lines the code repeated two more times with different numbering for the screenshot name. I will come back to this project as the screenshots only able to show the GDPR prompt. So finding a way to fix this will likely solve most of the task.

https://www.tobiolabode.com/blog-1/2019/1/1/selenium-screenshots

--

--

Tobi Olabode
Tobi Olabode

Written by Tobi Olabode

tobiolabode.com Interested in technology, Mainly writes about Machine learning for now. @tobiolabode3

No responses yet