SitePoint
  • Premium
  • Library
  • Community
  • Save on SaaS
  • Jobs
  • Blog
LoginStart Free Trial
Preface
1

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:

Code snippet

from selenium.webdriver.common.keys import Keys

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

Code snippet

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:

Code snippet

print(driver.current_url)

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

Code snippet

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

Community Questions

Previous
Finish