SitePoint
  • Blog
  • Discord
  • Forum
  • Library
  • Login
Join Premium

Front-end Testing in Python: A Detailed Guide

Close
  1. Preface
    • Front-end Testing in Python: A Detailed Guide
    • Notice of Rights
    • Notice of Liability
    • Trademark Notice
    • About SitePoint
  2. 1Front-end Testing in Python: A Detailed Guide
    • Prerequisites
    • Getting Started with Selenium
    • Working with Forms in Selenium
    • Integrate Selenium with Python Unit Tests
    • Integrate Selenium with Django and Flask
    • Selenium Testing on the Cloud
    • Challenges with Selenium
    • Final Thoughts

You don't have any bookmarks for this book yet.

Front-end Testing in Python: A Detailed Guide

Fill and Submit with Forms

Once you’ve been able to select a form or an input element, you can now fill and submit it. To fill a form through Selenium, you need to emulate keystrokes on your keyboard. You need to make an additional import as shown below to perform this operation:

from selenium.webdriver.common.keys import Keys

Let’s now fill the search form and submit it:

search_bar = driver.find_element_by_id("id-search-field")search_bar.clear()search_bar.send_keys("django")search_bar.send_keys(Keys.RETURN)

If you’re performing this test on Chrome, you’ll notice the form being filled in through Selenium, and the form being submitted. Once the search results are displayed, you can verify if the URL of the current page has changed with the following:

print(driver.current_url)

The output should reflect the same URL that you can see in the open browser window:

https://www.python.org/search/?q=django&submit=
End of PreviewSign Up to unlock the rest of this title.

Community Questions