How to click button selenium python

0 votes

How to click button selenium python?

<button id="sample_editable_1_new" class="btn sbold green" onclick="document.location.href='customeradd.php'">
                                                    Add New
                                                    <i class="fa fa-plus"></i>


Got Error : raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[@id='sample_editable_1_new']"}
  (Session info: chrome=86.0.4240.75)

Oct 14, 2020 in Python by ParthivPatel
• 140 points

2 answers to this question.

0 votes

Hey, @Parthiv,

For python, use the

from selenium.webdriver import ActionChains


answered Oct 14, 2020 by Gitika
• 65,970 points
0 votes

Selenium can automatically click on buttons that appear on a webpage

  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, then after finding the button/element we can click on it using click() method.

Syntax :

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

# clicking on the button


import time

# importing webdriver from selenium

from selenium import webdriver


# Here Chrome  will be used

driver = webdriver.Chrome()

# URL of website

url = "https:// ABC.."


  # Opening the website



# geeting the button by class name

button = driver.find_element_by_class_name("slide-out-btn")


# clicking on the button

This will click on the button and a popup will be shown. For further understanding, you can refer to the Selenium Training.

Hope this helps!!!

answered Oct 14, 2020 by Danish Bhatiya

Related Questions In Python

+1 vote
2 answers

How to automate image upload from my computer to site using python-selenium?

Hey, this code worked for me: image_path=os.path.abspath('.\\folder1\\subfolder2\file1.jpg') driver.find_element_by_id("Id of ...READ MORE

answered Aug 19, 2019 in Python by Rishi
0 votes
0 answers
0 votes
0 answers

How to click on the main menu and sub menu using python script

How to proceed with main menu and ...READ MORE

Oct 6, 2020 in Python by ParthivPatel
• 140 points
+2 votes
2 answers

How to make a laplacian pyramid using OpenCV python?

down voteacceptTheeThe problem is that you're iterating ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,780 points
+3 votes
5 answers

How to read multiple data files in python

Firstly we will import pandas to read ...READ MORE

answered Apr 6, 2018 in Python by DeepCoder786
• 1,720 points
+4 votes
7 answers
+1 vote
3 answers

How can I use python to execute a curl command?

For sake of simplicity, maybe you should ...READ MORE

answered Oct 11, 2018 in Python by charlie_brown
• 7,780 points
+1 vote
10 answers

How to fix this? ValueError: invalid literal for int() with base 10 error in Python

Just for the record: >>> int('55063.000000') Traceback (most recent ...READ MORE

answered Aug 17, 2020 in Python by pakainfo
• 200 points