Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find button with Selenium by its text inside (Python)?

I have the following three buttons that I can't figure out how to grab the text that is inside of them (e.g Outliers). I tried browser.find_element_by_link_text("Outliers").click(), but got "Unable to locate element" error. How can I do it?

enter image description here

like image 213
sprogissd Avatar asked Apr 18 '18 18:04

sprogissd


People also ask

How do I find an element that contains specific text in Selenium Webdriver Python )?

We can find an element that contains specific text with Selenium webdriver in Python using the xpath. This locator has functions that help to verify a specific text contained within an element. The function text() in xpath is used to locate a webelement depending on the text visible on the page.

How do you select a button in Selenium Python?

We can click a button with Selenium webdriver in Python using the click method. First, we have to identify the button to be clicked with the help of any locators like id, name, class, xpath, tagname or css. Then we have to apply the click method on it. A button in html code is represented by button tagname.

How do I search text in Selenium?

text() and contains methods text(): A built-in method in Selenium WebDriver that is used with XPath locator to locate an element based on its exact text value. contains(): Similar to the text() method, contains() is another built-in method used to locate an element based on partial text match.


1 Answers

Another example XPath:

browser.find_element_by_xpath('//button[text()="Outliers"]') 
like image 70
jmunsch Avatar answered Sep 22 '22 13:09

jmunsch