How to click a button on webpage using selenium ?
Last Updated :
23 Feb, 2024
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 :
- Find the button.
- 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
from selenium import webdriver
driver = webdriver.Chrome()
driver.get(url)
button = driver.find_element_by_class_name( "slide-out-btn" )
button.click()
|
This will click on the button and a popup will be shown.Â
Output –Â
Â
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...