Search code examples
pythonselenium-webdriverbrowserclickvisible

How to click a button with visible text (python selenium)?


I am trying to click to a button which has a visible text but I can't find a way.how it looks like . I am trying to click to the "laebel 41" but I need to click by detecting visible text


Solution

  • In order to click on the label element try this:

    driver.find_element_by_xpath("//label[contains(text(),'41')]").click()
    

    In order to click on input sibling element try this:

    driver.find_element_by_xpath("//label[contains(text(),'41')]/..//input").click()
    

    Don't forget to add some wait / delay before accessing the element to make it loaded.