driver.get(url)
Browse / Selenium Testing & Debugging Cheatsheet
Selenium Testing & Debugging Cheatsheet
A quick reference for testing and debugging web applications using Selenium, covering common commands, debugging techniques, and best practices.
Core Selenium Commands
      
        
            Basic Navigation
        
      
    
  |  | Loads a new web page. | 
| 
 | Returns the URL of the current page. | 
| 
 | Returns the title of the current page. | 
| 
 | Refreshes the current page. | 
| 
 | Navigates to the previous page in history. | 
| 
 | Navigates to the next page in history. | 
      
        
            Element Interaction
        
      
    
  | 
 | Simulates typing into an element. | 
| 
 | Clicks on an element. | 
| 
 | Clears the text of an input or textarea element. | 
| 
 | Gets the value of an element’s attribute. | 
| 
 | Gets the visible text of the element. | 
| 
 | Checks if the element is currently displayed. | 
      
        
            Finding Elements
        
      
    
  | 
 | Finds an element by its ID. | 
| 
 | Finds an element by its name attribute. | 
| 
 | Finds an element by its class name. | 
| 
 | Finds an element by its tag name. | 
| 
 | Finds a link by its exact text. | 
| 
 | Finds a link by a partial match of its text. | 
Advanced Selenium Techniques
      
        
            Explicit Waits
        
      
    
  | 
 | Waits until an element is present in the DOM. | 
| 
 | Waits until an element is visible. | 
| 
 | Waits until an element is clickable. | 
| 
 | Waits until specific text is present in the element. | 
| 
 | Waits until the page title contains specific text. | 
| 
 | Waits until an alert is present. | 
      
        
            Handling Alerts and Popups
        
      
    
  | 
 | Switches the context to the currently active alert. | 
| 
 | Accepts the alert (clicks ‘OK’). | 
| 
 | Dismisses the alert (clicks ‘Cancel’). | 
| 
 | Sends text to the alert prompt. | 
| 
 | Gets the text of the alert. | 
| 
 | Switches back to the main document content. | 
      
        
            Executing JavaScript
        
      
    
  | 
 | Executes JavaScript in the current browser context. 
 | 
| Example:  | Scrolls to the bottom of the page. | 
| Example:  | Clicks on a specific element using JavaScript. | 
Debugging Techniques
      
        
            Common Exceptions
        
      
    
  | NoSuchElementException: Element not found. 
 | 
| TimeoutException: Element not found within the specified time. 
 | 
| ElementNotInteractableException: Element is not clickable or visible. 
 | 
| StaleElementReferenceException: Element is no longer attached to the DOM. 
 | 
      
        
            Debugging Strategies
        
      
    
  | 
 driver.save_screenshot(“error.png”) | 
| 
 | 
| 
 import logging | 
| 
 import pdb; pdb.set_trace() | 
      
        
            Selenium Grid
        
      
    
  | Selenium Grid allows running tests in parallel across different browsers and operating systems. It consists of a Hub and Nodes. |  | 
| Hub: Central point that receives test requests and distributes them to available nodes. |  | 
| Nodes: Registers with the Hub and provides the browsers and OS environments for running tests. |  | 
Best Practices
      
        
            Code Maintainability
        
      
    
  | 
 | 
| 
 | 
| 
 | 
      
        
            Test Reliability
        
      
    
  | 
 | 
| 
 | 
| 
 | 
      
        
            Parallel Execution
        
      
    
  | 
 | 
| 
 | 
