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
1,400 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,870 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.

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
2,252 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
299 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,780 points
3,187 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
11,859 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,780 points
63,717 views
+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
231,956 views