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 in Python by ParthivPatel
• 140 points
72 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 by Gitika
• 49,540 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 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
1,696 views
0 votes
0 answers
0 votes
0 answers
+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
2,937 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
10,571 views
+4 votes
7 answers
+1 vote
8 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 in Python by pakainfo
• 200 points
182,153 views
0 votes
1 answer

how to play audio highlights his text in python?

Hey, You can split the audio files into ...READ MORE

answered Mar 27 in Python by Gitika
• 49,540 points
284 views