Handling Race Conditions

In our previous tutorial, we upgraded our POM to include a Base page object to handle all common methods related to the browser interaction.

In this tutorial, we are going to add additional logic to handle race conditions, which is the effect of elements not being ready/loaded when the script is executed.

Although in our base project, it is not required, we will be adding that logic for guidance and thinking on escalating our project.

Update the Base Page as follows (explanation below):

image.png

1. Importing required libraries.
2. WebDriverWait implementation: We include the return statement in the same line for clarity. Also, we applied the same change to the `get_elements` method below.

Done! Because we have a separate method to just get the element, we only needed to refactor that method, and all subsequent methods that use that one will be handling race conditions now.

NOTE: There's a change required in a SELECTOR in the RESULT page. the LINK_DIVS should look like: LINK_DIVS = (By.CSS_SELECTOR, "a.result__a"). This has nothing to do with this tutorial but causes failure when running. I'll eventually update the source code and remove this note :)