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 Working with Radio buttons and Check boxes in Selenium with 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 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 Working with Radio buttons and Check boxes in Selenium with Python Prerequisite: Browser Automation Using Selenium Requirement: You need to install chrome driver and set path. Click here to download. Selenium is an effective device for controlling an internet browser through the program. It is purposeful for all browsers, works on all fundamental OS and its script 1 min read How to Automate Click Using Selenium WebDriver? Selenium is one of the most popular and powerful tools for automating web applications. Selenium is widely used for automating user interactions like filling out forms, clicking on a button, navigating to a web page, and many more. One of the most common tasks while working with Selenium is clicking 5 min read Like