Is it possible to select button with only class values in Selenium Python? The html is as follows:
<button class="secondary option-action ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"
from selenium import webdriver
browser = webdriver.Firefox()
browser.get(any_url)
Any idea to select that button?
Yes, it is possible.
Use find_element_by_class_name
(or find_elements_by_class_name
to get multiple matched elements):
browser.find_element_by_class_name('secondary')
You can also use find_element_by_css_selector
(or ..s variant):
browser.find_element_by_css_selector('.secondary')
Alternatively you can also use find_element_by_xpath
, but it requires a verbose xpath expression to be precise:
xpath = "descendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), ' secondary ')]"
browser.find_element_by_xpath(xpath)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With