Background:
The emergence of modern single-page applications (SPAs) based on React, Angular, Vue has led to new problems in UI test automation: asynchronous data loading, complex dynamic UI elements, client-side routing. Classic approaches (e.g. by selectors or statically rendered DOM) have become unreliable for such applications.
Problems:
Solutions:
from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC wait = WebDriverWait(driver, 20) my_element = wait.until(EC.visibility_of_element_located((By.ID, 'dynamic_id')))
Key Features:
Can you rely only on XPATH or CSS locators in tests for SPA?
No. XPATH/CSS locators often break with any changes in the DOM. It is better to use stable data-* attributes or test-ids specifically embedded in the elements.
Does Selenium/WebDriverWait solve all async issues?
No. WebDriverWait helps to avoid fails due to delays, but does not guarantee correct loading and the state of complex UIs. Additional checks, API mocking, and handling of UI states are required.
Is it enough to only check for the presence of visible elements on the page to confirm the UI loaded correctly?
No. You can mistakenly take an "empty" load as successful if the element is displayed but does not contain expected data or state. You need to validate the content and values of fields.
Automated tests run on a schedule, use XPath selectors and sleep delays. After the UI update, half of the tests fail due to the absence of elements or their displacement with new id/class.
Pros:
Cons:
Data-testids are embedded in the UI, tests use explicit waits and special test hooks. All network responses are mocked, and tests validate not only presence but also content of elements.
Pros:
Cons: