簡體   English   中英

可以使用哪種 Selenium 方法或命令來單擊以下按鈕?

[英]Which Selenium method or command can be used to click on the following buttons?

Selenium with python 中的哪個方法可以用來點擊下面的按鈕?

按鈕編號 1:

<a href="/help.html"> = $0
<i class="fa fa-question" aria-hidden="true"></i> HELP </a>

按鈕編號 2:

<a class="active-menu-item" href="/help/making_service_requests.html">Service Requests</a>

按鈕編號 3:

<a href="/help/making_service_requests/transferring_service.html">Transfer Service</a>

我已經嘗試過但不會工作:

driver.find_element_by_xpath('//*[@id="topmenuheader"]/div/ul/li[3]/a').click()
driver.find_elements_by_partial_link_text("Transfer Service").click()
driver.find_element_by_class_name("btn").click()

我遇到過很多實例,其中沒有 id、沒有類等,但是沒有可用的 href 或帶有 html 引用的 href 如上所述。 這些似乎很棘手,因為我已經嘗試了很多東西。 也許你們中的一些人遇到過這些並且可以提供幫助。 謝謝

這些應該適用於這 3 個元素。 我展示了通過 href、類或文本獲取這些標簽的多種方法。

driver.find_element_by_xpath("a[@href='/help.html']").click()
driver.find_element_by_xpath("a[@class='active-menu-item']").click()
driver.find_element_by_xpath("a[text()='Transfer Service']").click()

你可以這樣做 :

Driver = driver.find_element_by_xpath("path here")
Driver.click()

暫無
暫無

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

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