Click button by text using Python and Selenium Last Updated : 03 Mar, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Selenium is a tool that provides APIs to automate a web application to aid in its testing. In this article, we discuss the use of Selenium Python API bindings to access the Selenium WebDrivers to click a button by text present in the button. In the following example, we take the help of Chrome. The method used is the find_element_by_link_text() which scrapes the element using the text present. In case there is no such element with the given text attribute, NoSuchElementException is returned. Installation: Make sure you have Selenium installed using pip3 install Selenium And also download the WebDriver for your web browser : Chrome : https://chromedriver.chromium.org/downloads Firefox : https://github.com/mozilla/geckodriver/releases Safari : https://webkit.org/blog/6900/webdriver-support-in-safari-10/ Once Selenium is installed along with the desired WebDriver, we create a file script.py and using our code editor write the python script below which opens up the geeksforgeeks website using the Selenium WebDriver and clicks the Sign In button using the link text. Syntax: driver.find_element_by_link_text("sample text") Steps by step Approach: Import required modules.Create webdriver object.Assign URL.Use maximize_window() method to maximize the browser window. And then wait 10 seconds using sleep() method.Use find_element_by_link_text() method to click button by text. Below is the implementation. Python3 # import module from selenium import webdriver import time # Create the webdriver object. Here the # chromedriver is present in the driver # folder of the root directory. driver = webdriver.Chrome(r"./driver/chromedriver") # get https://www.geeksforgeeks.org/ driver.get("https://www.geeksforgeeks.org/") # Maximize the window and let code stall # for 10s to properly maximise the window. driver.maximize_window() time.sleep(10) # Obtain button by link text and click. button = driver.find_element_by_link_text("Sign In") button.click() Output: First, the WebDriver opens up the window with geeksforgeeks, maximizes it, and waits for 10 seconds. Then it clicks the Sign In button and opens up the sign-up panel. Comment More infoAdvertise with us Next Article Get all text of the page using Selenium in Python A archismangh007 Follow Improve Article Tags : Python Python-selenium Python Selenium-Exercises Practice Tags : python Similar Reads Click the Button by Text Using java and Selenium One common action testers need to perform is to click buttons by text using Java and Selenium. This method is particularly useful when buttons lack unique identifiers like IDs or classes. By applying Selenium powerful locators, you can easily locate buttons based on their displayed text, ensuring yo 3 min read Python Selenium - Find Button by text In this article, let's discuss how to find a button by text using selenium. See the below example to get an idea about the meaning of the finding button by text. Example: URL: https://html.com/tags/button/ We need to find the "CLICK ME!" button using the text "Click me!". Module Needed: Selenium: Th 2 min read How to click a button on webpage using Selenium? This article is all about how to click any button using Selenium on a webpage and many more concepts related to the same which are discussed below. Table of Content What is Selenium? How to click on a button using Selenium Conclusion Frequently Asked Questions on How to click a button on webpage usi 2 min read Get all text of the page using Selenium in Python As we know Selenium is an automation tool through which we can automate browsers by writing some lines of code. It is compatible with all browsers, Operating systems, and also its program can be written in any programming language such as Python, Java, and many more. Selenium provides a convenient A 3 min read How to Locate Elements using Selenium Python? Selenium: is an open-source tool that automates web browsers. It provides a single interface that lets you write test scripts in programming languages like Ruby, Java, NodeJS, PHP, Perl, Python, and C#, among others. I personally prefer Python as itâs very easy to write code in python. A browser-dri 3 min read Python - Opening links using Selenium Selenium is a powerful tool for controlling the web browser through the program. It is functional for all browsers, works on all major OS and its scripts are written in various languages i.e Python, Java, C#, etc, we will be working with Python. Selenium Python bindings provide a convenient API to a 2 min read Like