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>
                                                </button>

self.driver.find_element_by_xpath("//button[@id='sample_editable_1_new']").click()


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
28,729 views

2 answers to this question.

0 votes

Hey, @Parthiv,

For python, use the

from selenium.webdriver import ActionChains

and

ActionChains(browser).click(element).perform()
answered Oct 14, 2020 by Gitika
• 65,770 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
button.click()

CODE:

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

driver.get(url)

  

# geeting 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. 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
6,233 views
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
1,445 views
+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,720 points
4,905 views
+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
15,277 views
+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,720 points
94,419 views
+2 votes
10 answers

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

The following are totally acceptable in python: passing ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,560 points
409,222 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP