简体   繁体   中英

Problem with find element to click in a filter button - SELENIUM

I'm trying to automate a task in my job with Selenium. Everything was going fine until I had to click in a filter button.

I tried with find_element_by_xpath but it went wrong. (I tried CSS selector and link text and it also went wrong).

I'm stuck in that part. Could someone help this desperate brazilian girl? lol

Things that I tried:

 nav.find_element_by_css_selector('.btn-lg').click()

Error: NoSuchElementException: Message: no such element: Unable to locate element: {"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()

Error: NoSuchElementException: Message: no such element: Unable to locate element: {"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 from the button:

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

AND

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

Thanks!

Try this

driver.find_element_by_xpath(".//button[@title='Filtros']").click()

Try this Xpath

'//button[@ng-click="openFilters()"]'

or this

'//button[@title="Filtros()"]'

or

'//button[@title="Filtros()" and (@ng-click="openFilters()")]'

In case your element is inside the iframe you need to do something like following:

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

I mentioned the iframe here according to it's tag name. Possibly you will need to use some other locator, according to the actual locator suitable in your case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM