About Testing Forms with Selenium

When testing form fields with Selenium, you have two options: send key presses to HTML elements or perform clicks on them.

Sending key presses if often more reliable, because clicking requires the element to be in the visible area of the browser view.

DON'T:

1
2
3
browser.find_element(
    by=By.ID, value="id_privacy_policy"
).click()

DO:

1
2
3
browser.find_element(
    by=By.ID, value="id_privacy_policy"
).send_keys(" ")

P.S. On the contrary, Playwright lets you handle the clicks even in areas outside of visible viewport (it scrolls to the element automatically).

Tips and Tricks Testing Django 5.x Django 4.2 Django 3.2 Selenium