Take Screenshot in Selenium Python

Profile picture for user arilio666
Submitted by arilio666 on

To capture a screenshot in Python, utilize the screenshot method supplied by the WebDriver class.

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium. web driver.support.UI import WebDriverWait
from selenium. web driver.support import expected_conditions as EC
from selenium. web driver.common.action_chains import ActionChains

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
att = driver.find_element(By.XPATH,"//a[normalize-space()='Groups']").get_attribute('title')
if att == "Explore our groups.":
   print('Tooltip verified')
   print('Wrong Tooltip Text')
  • We begin by importing the Selenium package's web driver module. 
  • Then, using the Chrome driver, we create a new instance of the WebDriver. 
  • Following that, we travel to a webpage by invoking the get method and giving the URL of the webpage, and then we perform a simple tooltip verification.
  • To take a screenshot, we call the driver's save_screenshot method, giving the appropriate filename and extension (in this example, "Luffy.png"). 
  • The screenshot will be saved in the currently selected working directory.
Take Screenshot in Selenium Python