Bostan
Bostan

Reputation: 77

How to click on the text button using selenium python

Hi I'm trying to click on select button using xpath and css selector but it doesn't works

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 it would be here is the code

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

Upvotes: 6

Views: 1657

Answers (2)

Sarfraz
Sarfraz

Reputation: 108

You're using elements that will not work. Use element instead. I am sure it will work.

Upvotes: 1

JRodDynamite
JRodDynamite

Reputation: 12623

Keep it simple.If there is a single button then try:

Example 1 -

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

If multiple buttons with same class name then 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 a frame, then make sure you switch to the frame before clicking on it.

Upvotes: 0

Related Questions