簡體   English   中英

Selenium找到提交按鈕

[英]Selenium locate submit button

我正在使用Python中的selenium腳本,我在這個階段試圖找到一個提交按鈕。

HTML

<div class="submit-buttons">
<button class="submit" type="submit">Filter</button>
</div>

我試過了,但這沒效果。
所以我沒有解決方案:

browser.find_element_by_partial_link_text('Filter').click()
browser.find_element_by_link_text('Filter').click()
browser.find_element_by_class_name('submit').click()

試試xpath解決方案:

driver.find_element_by_xpath('//div[@class="submit-buttons"]/button[@class="submit"]')

如果它仍未識別,則元素可能在框架內,並且您必須在找到元素之前切換到該框架。

通過鏈接文本或部分鏈接文本定位器將僅使用鏈接 - a元素 這里有一個按鈕。 如果要使用按鈕文本,請使用以下“by xpath”定位器:

//button[. = "Filter"]

這段代碼應該有效:

driver.find_element_by_xpath('//button[text()='Filter']')
driver.findElement(By.cssSelector("button[type=\"submit\"]")).click();

暫無
暫無

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

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