簡體   English   中英

Python Selenium 使用按鈕文本單擊 span 標簽內的按鈕

[英]Python Selenium Click button inside span tag using button text

下面的 html 文本退出頁面。 我想讓 selenium 單擊此標簽所指的按鈕。 我無法搜索此 href,因為給定應用程序的 ID 未知,鏈接將始終具有不同的 ID。 我必須通過在“新建數據庫/服務器”按鈕內的文本中找到它來單擊此按鈕

<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> 

如何讓驅動程序 go 指向此 href 鏈接?

使用以下xpath點擊按鈕。

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

或使用 link_text

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM