Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python Selenium Click button inside span tag using button text

The html text below exits on a page. I am trying to have selenium click the button that this tag is referring to. I can not search this href because the id for given app is unknown and link will always have a different id. I have to click on this button by locating it by text inside button which is "New Database/Server"

<a class="btn btn-primary" data-turbo-frame="modal" href="/repo/servers/new?repo_application_id=280"><svg class="bi flex-shrink-0 me-2" height="24" role="img" width="24"><use href="#icon_database-plus"></use></svg><span class="pe-3">New Database/Server</span></a> 

How do I have the driver go to this href link?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use following xpath to click on the button.

driver.find_element(By.XPATH, "//a[.//span[text()='New Database/Server']]").click()

or use link_text

driver.find_element(By.LINK_TEXT, "New Database/Server").click()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading