How to click on a text button using selenium python

Hi, I am trying to press the select button using the xpath and css switch, but it does not work.

browser.find_elements_by_xpath('//div[@class="section-select-all"]').click() browser.find_elements_by_css_selector('#results-container > form > ul > li:nth-child(1) > div > div > button').click() browser.find_elements_by_xpath('//*[@id="results-container"]/form/ul/li[1]/div/div/button').click() 

please let me know how this code will be here

 <div class="section-actions"><button type="button" class="section-select-all">Select 50<span class="screen-reader-text"> for section Dec 11, 2015</span></button></div> 
+6
source share
2 answers

You are using elements that will not work. Use element instead. I am sure this will work.

+1
source

Keep it simple. If there is one button, try:

Example 1 -

 browser.find_element_by_class_name("section-select-all").click() 

If there are multiple buttons with the same class name, you can use this:

Example 2 -

 buttons = browser.find_elements_by_class_name("section-select-all") for button in buttons: button.click() 

If the buttons are in the frame, make sure you switch to the frame before clicking on it.

0
source

All Articles