简体   繁体   中英

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>

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

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.

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