ProCodebaseProCodebase
  • ModusA Growth OS for your business, on WhatsAppKiosqSell more. Chase less.AI InterviewerAutomated screening & AI-led interviewsXperto AIAI prep companion for candidatesAI Tools HubResume builder, learning paths & more
  • Pre-Vetted DevelopersScreened, scored and ready to interviewAI-Native DevelopersSenior engineers on an hourly basis
  • Services
  • Features
  • AI Coaching
  • Jobs
  • FAQs
Sign inBook a demo
  • Services
  • Features
  • AI Coaching
  • Jobs
  • FAQs
Sign inBook a demo
ProCodebaseProCodebase

ProCodebase Technologies builds AI products for hiring and growth, and ships software for clients as a technical consultancy. We source, screen and deliver pre-vetted developers — so you only interview high-signal candidates.

Products

  • Modus
  • Kiosq
  • AI Interviewer
  • Xperto AI
  • AI Tools Hub

Hire & build

  • Pre-Vetted Developers
  • AI-Native Developers
  • Technical Consultancy
  • MVP Development
  • Features

Resources

  • Articles
  • Topics
  • Certifications
  • Collections
  • Jobs

Company

  • About Us
  • Contact Us
  • Book a Demo
  • FAQs

© 2026 ProCodebase Technologies. All rights reserved.

  • Privacy Policy
  • Terms & Conditions
  • Refund & Cancellation

Level Up Your Skills with Xperto-AI

A multi-AI agent platform that helps you level up your development skills and ace your interview preparation to secure your dream job.

Launch Xperto-AI

Selenium Interacting with Web Elements

author
Generated by
Hitendra Singhal

21/09/2024

Selenium

Sign in to read full article

Selenium is an open-source automation tool that allows developers and testers to automate browser activities seamlessly. One of the core functionalities of Selenium is its ability to interact with web elements. In this blog, we will discuss three primary actions you can perform on web elements: Click, Send Keys, and Select.

1. Click

The Click action is one of the most frequently used interactions in Selenium. It allows you to simulate a mouse click on web elements, like buttons or links. This is essential for navigating through a web application or triggering particular events.

Example of Click Action:

from selenium import webdriver from selenium.webdriver.common.by import By # Initiate the browser driver = webdriver.Chrome() # Open a webpage driver.get('https://example.com') # Locate the button by its ID and click it button = driver.find_element(By.ID, "submit-button") button.click() # Close the browser driver.quit()

In this example, we initiate a Chrome browser, navigate to a sample webpage, locate the button with ID "submit-button," and perform the click action.

2. Send Keys

The Send Keys action simulates typing into web elements such as text fields or text areas. This is necessary when inputting data, such as filling out forms or search boxes.

Example of Send Keys Action:

from selenium import webdriver from selenium.webdriver.common.by import By # Initiate the browser driver = webdriver.Chrome() # Open a webpage driver.get('https://example.com/login') # Locate the username field and send keys username_field = driver.find_element(By.NAME, "username") username_field.send_keys("myUsername") # Locate the password field and send keys password_field = driver.find_element(By.NAME, "password") password_field.send_keys("myPassword") # Close the browser driver.quit()

In this example, we navigate to a login page and locate the username and password fields. Using the Send Keys method, we input our credentials for authentication.

3. Select

When working with dropdown menus, you will need to use the Select class from Selenium. This allows you to choose options from <select> HTML elements efficiently.

Example of Select Action:

from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select # Initiate the browser driver = webdriver.Chrome() # Open a dropdown page driver.get('https://example.com/form') # Locate the dropdown element dropdown = Select(driver.find_element(By.ID, "options")) # Select by visible text, index or value dropdown.select_by_visible_text("Option 1") # dropdown.select_by_index(0) # Select the first item # dropdown.select_by_value("value1") # Select by the option value # Close the browser driver.quit()

In this code snippet, we navigate to a web page that features a form with a dropdown list. We locate the dropdown by its ID and use the Select class to choose an option by its visible text.

By mastering these three fundamental actions—Click, Send Keys, and Select—you can significantly enhance your web automation scripts in Selenium. Each of these methods opens the door to mimic real user behavior within your automated tests while ensuring a dynamic interaction with your application's web elements.

Popular tags

SeleniumWeb AutomationUI Testing

Share now!

Like & bookmark

Related collections

  • Mastering Selenium WebDriver: Automation Testing Essentials

    21/09/2024 · UI Automation

  • Mastering UI Automation: Practical Guide

    18/09/2024 · UI Automation

Related articles

  • Mastering Selenium with Page Object Model Design Pattern

    21/09/2024 · UI Automation

  • CI/CD Integration for Automated Tests

    18/09/2024 · UI Automation

  • Best Practices for Selenium Testing

    21/09/2024 · UI Automation

  • Understanding Web Elements and Selectors

    18/09/2024 · UI Automation

  • Selenium Introduction

    15/09/2024 · UI Automation

  • Selenium Locating Elements

    21/09/2024 · UI Automation

  • Selenium Parallel Test Execution with TestNG

    21/09/2024 · UI Automation

Popular category

  • Python
  • Generative AI
  • Machine Learning
  • ReactJS
  • System Design