6

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>
2
  • How many buttons you want clicked? Commented Dec 30, 2015 at 10:16
  • If you have issues with the Xpath or CSS queries, you can use the developer tools in Chrome and Firefox to check that your desired web element gets selected. Simply use the console and type $$("CSS query") or $.x("XPath query") Commented Dec 30, 2015 at 11:00

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

3 Comments

AttributeError: 'list' object has no attribute 'click'
@Bostan - I hope browser = webdriver.Firefox() Or chrome.
@Bostan - Please make sure the spelling of element[s] is correct. In the first example, I used example and in the second I used elements. If you want to click on elements then you need to iterate through the list (like I did in the 2nd example).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.