[英]Problem with find element to click in a filter button - SELENIUM
我正在嘗試使用 Selenium 自動化我的工作中的一項任務。 一切都很好,直到我不得不點擊一個過濾器按鈕。
我嘗試使用 find_element_by_xpath 但它出錯了。 (我試過 CSS 選擇器和鏈接文本,它也出錯了)。
我被困在那個部分。 有人可以幫助這個絕望的巴西女孩嗎? 哈哈
我嘗試過的事情:
nav.find_element_by_css_selector('.btn-lg').click()
錯誤:NoSuchElementException:消息:沒有這樣的元素:無法找到元素:{"method":"css selector","selector":".btn-lg"}
nav.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div/div[3]/div/div[2]/div[1]/div/div/form/div[1]/button').click()
錯誤:NoSuchElementException:消息:沒有這樣的元素:無法找到元素:{"method":"xpath","selector":"/html/body/div[4]/div/div[2]/div/div/ div[3]/div/div[2]/div[1]/div/div/form/div[1]/button"}
HTML 從按鈕:
<button type="button" class="btn btn-default btn-lg" title="Filtros" ng-click="openFilters()" ga-event="" ga-label="open-orders-filters"><span class="uim-filter-count badge">1</span> <i class="icon-filter"></i></button>
和
<div class="uim-btn-filter uim-filter-checked" ng-class="{ 'uim-filter-checked': filters.getAppliedFilters().length }"><button type="button" class="btn btn-default btn-lg" title="Filtros" ng-click="openFilters()" ga-event="" ga-label="open-orders-filters"><span class="uim-filter-count badge">1</span> <i class="icon-filter"></i></button></div>
謝謝!
嘗試這個
driver.find_element_by_xpath(".//button[@title='Filtros']").click()
試試這個 Xpath
'//button[@ng-click="openFilters()"]'
或這個
'//button[@title="Filtros()"]'
或者
'//button[@title="Filtros()" and (@ng-click="openFilters()")]'
如果您的元素位於 iframe 內,您需要執行以下操作:
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as wait
wait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(driver.find_element_by_tag_name("iframe")))
我在這里根據它的標簽名稱提到了iframe。 根據適合您情況的實際定位器,您可能需要使用其他定位器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.