how to find button to click in Selenium using python? -


</div> <fieldset class="pi-search-form__footer"> <div class="pi-search-form__footer-cta" data-ng-show="stay.isstandardbooking()"> <button class="btn btn--primary" data-ng-click="submitsearch()"> <span data-ng-switch="ctatext"> <span data-ng-switch-when="checkavailability">check availability</span> <span data-ng-switch-when="searchnow">search now</span> <span data-ng-switch-default data-pi-track-click="search_again">search</span> </span> </button> </div> 

this button code , want click "check availability" button. use code not works.

browser.find_elements_by_xpath(".//span[contains(text(), 'check availability')]") 

here answer question:

as want click on button xpath should unique , should identify single element. hence instead of find_elements_by_xpath should consider using find_element_by_xpath. click on check availability button can use following line of code:

//ensure imports selenium.webdriver.common.by import selenium.webdriver.support.ui import webdriverwait selenium.webdriver.support import expected_conditions ec //other code //click on check availability button webdriverwait(driver, 5).until(ec.element_to_be_clickable((by.xpath, "//button[@class='btn btn--primary']//span[@data-ng-switch-when='checkavailability']"))) browser.find_element_by_xpath("//button[@class='btn btn--primary']//span[@data-ng-switch-when='checkavailability']").click() 

let me know if answers question.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -