top of page
Pink Marble

Get over it! Simple solutions to overcome elements in automation tests

Jul 18, 2024

2 min read

When I worked on my automation project, one of the tasks I had to overcome was handling elements that are difficult to interact with, such as alerts, pop-ups, and dropdowns.


At first, I thought maybe I didn't identify the element correctly, so I tried again by - ID, Name, Css Selector, XPath.

When that didn't help, I realized I needed to try a different approach.

So, I researched and read up on it, and eventually, I succeeded.


It was important to me to succeed on my own, without using AI.

(Don’t get me wrong,  AI is very helpful when needed, if used correctly.)


 

Here are a few examples from my project:


Problem: Element Not Interactable

Example: You are trying to click a button, but you get an -ElementNotInteractableException.

Solution: Ensure the element is visible and enabled before interacting with it.


Python code, element_to_be_clickable

 

Problem: Element Not Found

Example: You are trying to find an element but get a NoSuchElementException

Solution: Use explicit waits to allow time for the element to appear


Python code, presence_of_element_located

 

Problem: Handling Pop-ups and Alerts

Example: You need to handle a JS alert or pop-up

Solution: Switch to the alert and insert text/accept/dismiss it


Python code, switch_to_alert

 

Here is the alert text box from my project, I needed to insert some text in order to move forward:


My project page, alert text box

Click to watch the alert text box:



 

In this case I needed to wait for the pop-up to be visible and clickable in order to close it:


Pop-up from jerusalem.muni site

Click to watch the pop-up:




 

Problem: Handling Dropdowns

Example: You need to select an option from a dropdown menu

Solution: Use the Select class from selenium.webdriver.support.ui


Python code, dropdown select by visible text, value and index

This is the dropdown from my project:


Dropdown from my project page


 

So...did you get over it?




Jul 18, 2024

2 min read

Comments

Share Your ThoughtsBe the first to write a comment.
bottom of page