Start Selenium Testing with Python: Automated Testing of a User Signup/Login Form

On This Page Introduction to SeleniumPrerequisit

March 26, 2026 · 6 min read · Tool Comparison

Start Selenium Testing with Python: Automated Testing of a User Signup/Login Form

User hallmark in web applications ensures unafraid access to services. Testing signup and login sort with Selenium in Python lets you verify form functionality, battlefield validations, error messages and authentication flow across several browsers. Teams can detect issues earlier in development by automating these tests.

Introduction to Selenium

Seleniumis a tool that allows developers to automate web browser activity with exclusively a few lines of codification across multiple platforms.nIn the software testing ecosystem, it allows users to use different web pages and simulate end-user behavior to a great extent.

Some things that can be accomplished with Selenium include, but are not limited to:

  • Clicking buttons
  • Performing detent
  • Inputting schoolbook
  • Extracting text
  • Accessing Cookies
  • Pressing key

Prerequisites & # 8211; Initial Setup Process

Before the user starts writing codification, the following steps are needed for setup of Selenium and Python:

Step 1 & # 8211; Install Python 3.7

brew install python

Step 2 & # 8211;The Selenium faculty require a WebDriver to depart playing with the browsers. Supported browsers are:

  • Chrome
  • Edge
  • Firefox
  • Internet Explorer
  • Safari

In Selenium 4, you can straightaway use the Driver manager without adding any additional driver file in the undertaking. For that you have to install employ below command:

pip install webdriver-manager

Step 3 & # 8211;Install theSelenium packageemploy pip.

pip install selenium

Read More:

Selenium Python Test Example: How to open a webpage on Chrome Browser

Once the Selenium environment apparatus is accomplished, run a basic test using Selenium Python. Open your preferred text editor/IDE and type the followers:

from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome (ChromeDriverManager () .install ()) driver.get (`` https: //bstackdemo.com/ '') mark (browser.title) browser.close ()

This open a Chrome browser, navigates tohttps: //bstackdemo.com/and extracts the rubric using the methods available on our newly strike browser object. Now the exploiter can query DOM utilise different method defined in the browser object.

However, the question remains: How will the exploiter know to query?

Answer this by opening a web browser and expend the developer tool to scrutinise the substance on a web page. Suppose the user intends to search for the “Sign In” push on the BStack Demo abode page and click on it so that it redirect to the following page. By inspecting the BStack Demo domicile page, one will see that the push has the CSS dimension#signin. Add these lines after the get method vociferation.

signin_btn = driver.find_element (by=By.CSS_SELECTOR, value= '' # signin '') signin_btn.click ()

Now, everything look to be working. The exploiter can see the new page after clicking on the push.

Talk to an Expert

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

Learn Browser Automation with Selenium Python

The above test has validated that browsers can be automated using Python. Now, one can automate the procedure of ratify up as a new user and model the user experience. To start, navigate to https: //bstackdemo.com/ and start exploring browser developer tools.

One can unambiguously place the Sign In Button and can tick on it.

signin_btn = driver.find_element (by=By.CSS_SELECTOR, value= '' # signin '') signin_btn.click ()

The user should be able to see the username in the first field of the signin page.

username =driver.find_element (by=By.ID, value= '' username '')

Demonstrating the same thing using the python script

from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.by import By # Create a new illustration of the Chrome driver driver = webdriver.Chrome (ChromeDriverManager () .install ()) # Open the Bstack Demo website driver.get (`` https: //bstackdemo.com/ '') # Find the sign-in push and click on it signin_btn = driver.find_element (by=By.CSS_SELECTOR, value= '' # signin '') signin_btn.click () # Add inexplicit wait for element to be constitute driver.implicitly_wait (10) # Find the Username and affirm it ’ s profile username =driver.find_element (by=By.ID, value= '' username '') assert username.is_displayed ()

Also Read:

How to Automate Signup/Login Page Using Selenium in Python

Now, you have reached at the signup page. Here ’ s how you can commence automating Sign Up process. At 1st, you will detect all the uncommitted battleground locator using IDs.

username =driver.find_element (by=By.ID, value= '' username '') password =driver.find_element (by=By.ID, value= '' password '') login_btn= driver.find_element (by=By.ID, value= '' login-btn '')

As you can see, on click on the Username field, a tilt of usernames are obtained to take.

Same with the Password field,

So, add the locater for these demo username and password as easily.

username_input= driver.find_element (by=By.CSS_SELECTOR, value= '' # react-select-2-option-0-0 '') password_input =driver.find_element (by=By.CSS_SELECTOR, value= '' # react-select-3-option-0-0 '')

After selecting these values and clicking on the Login Button, you will be directed to the homepage again. But this clip, on the place of sign in button, you will see the Log Out Button. As shown in the below image.

For confirming the Signup Success, assert the visibility of Logout button.

logout_btn= driver.find_element (by=By.CSS_SELECTOR, value= '' # logout '') assert logout_btn.is_displayed ()

The final hand is below:

from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.by import By # Create a new instance of the Chrome driver driver = webdriver.Chrome (ChromeDriverManager () .install ()) # Open the Bstack Demo website driver.get (`` https: //bstackdemo.com/ '') # Find the sign-in push and click on it signin_btn = driver.find_element (by=By.CSS_SELECTOR, value= '' # signin '') signin_btn.click () # Add inexplicit wait for element to be found driver.implicitly_wait (10) # Find the Username, Password and Login Button username =driver.find_element (by=By.ID, value= '' username '') password =driver.find_element (by=By.ID, value= '' password '') login_btn= driver.find_element (by=By.ID, value= '' login-btn '') # Select demouser as Username username.click () username_input= driver.find_element (by=By.CSS_SELECTOR, value= '' # react-select-2-option-0-0 '') username_input.click () # Select testingisfun99 as Password password.click () password_input =driver.find_element (by=By.CSS_SELECTOR, value= '' # react-select-3-option-0-0 '') password_input.click () # Submit the form login_btn.click () driver.implicitly_wait (10) # Assert User is successfully Logged In logout_btn= driver.find_element (by=By.CSS_SELECTOR, value= '' # logout '') assert logout_btn.is_displayed () # Closer the browser driver.close ()

You can easy run this test script as common python file.

python file_name.py

Also Read:

How to build a class in Selenium Webdriver & amp; Python

Sometimes, you may have to use the like piece of code multiple times. It ’ s better to do away with indite codes repeatedly. Instead form it into a class to make your Web Automation code reusable and more manageable.

The Python script below shows how to build a class for web automation using. Here ’ s what it perform:

  • Initializes browser and navigates to BrowserStack
  • Signs up as a exploiter
  • Validates signup form
from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.by import By class WebAutomation: def __init__ (self): self.driver = webdriver.Chrome (ChromeDriverManager () .install ()) # Add implicit wait for element to be found def apply_wait (self): self.driver.implicitly_wait (10) # Navigate to Signup Page def open_signup_page (self): self.driver.get (`` https: //bstackdemo.com/ '') signin_btn = self.driver.find_element (by=By.CSS_SELECTOR, value= '' # signin '') signin_btn.click () # Select demouser as Username def fill_username (self): username=self.driver.find_element (by=By.ID, value= '' username '') username.click () username_input= self.driver.find_element (by=By.CSS_SELECTOR, value= '' # react-select-2-option-0-0 '') username_input.click () # Select testingisfun99 as Password def fill_password (self): watchword =self.driver.find_element (by=By.ID, value= '' password '') password.click () password_input =self.driver.find_element (by=By.CSS_SELECTOR, value= '' # react-select-3-option-0-0 '') password_input.click () # Submit the variety def submit_form (self): login_btn= self.driver.find_element (by=By.ID, value= '' login-btn '') login_btn.click () # Assert User is successfully Logged In def login_success (self): logout_btn= self.driver.find_element (by=By.CSS_SELECTOR, value= '' # logout '') assert logout_btn.is_displayed () self.driver.close () b1 = WebAutomation () b1.open_signup_page () b1.apply_wait () b1.fill_username () b1.fill_password () b1.submit_form () b1.apply_wait () b1.login_success ()

Also Read:

Conclusion

The experimentation described above is only a glance of what one can do with Selenium. Utilizing the full potentiality of Selenium and Python can go a long way in empowering developers and QAs to explore, automatize, and review web browser functionality.

By combine the power of Selenium Python & # 8217; s testing capabilities with extensive browser and device coverage, you can ensure comprehensive and reliable testing of your web application across different environments, browsers, and.

Useful Resources for Selenium and Python

Tags
22,000+ Views

# Ask-and-Contributeabout this matter with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free