The Wayback Machine - https://web.archive.org/web/20240206095532/https://www.geeksforgeeks.org/how-to-click-a-button-on-webpage-using-selenium/
Open In App
Related Articles

How to click a button on webpage using selenium ?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Selenium can automatically click on buttons that appear on a webpage. This article revolves around how to click any button using Selenium in a webpage. In order to do this there are two major steps we have to take :

  1. Find the button.
  2. Click on the button.

We can find the button on the web page by using methods like find_element_by_class_name(), find_element_by_name(), find_element_by_id() etc, following which we can click on it by using the click() method.

Syntax :  

# finding the button using ID
button = driver.find_element_by_id(ID)

# clicking on the button
button.click()

Code : 

Python3




import time
# importing webdriver from selenium
from selenium import webdriver
 
# Here Chrome  will be used
driver = webdriver.Chrome()
 
# URL of website
 
# Opening the website
driver.get(url)
 
# getting the button by class name
button = driver.find_element_by_class_name("slide-out-btn")
 
# clicking on the button
button.click()


This will click on the button and a popup will be shown. 
Output – 

 

Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century.

Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.


Last Updated : 26 Nov, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials