简体   繁体   中英

How to find an Element by index in selenium Webdriver for python

This is HTML code of that page

From there I want to access the 2nd element by using class name "maxbutton-1" as it has 3 same buttons and I can't use xpath or any constant selector so want to use the indexing with class and can't find anything to do that in python particular.

Also tried the method used in java to do same thing but it didn't worked.

Link of that same page

just trying to automate the movie downloading process for any movie.

Thank you.

To click on first, second or third button, try to change number of element:

el1 = driver.find_element_by_xpath("(//a[@class='maxbutton-1 maxbutton maxbutton-download-links'])[1]")

el2 = driver.find_element_by_xpath("(//a[@class='maxbutton-1 maxbutton maxbutton-download-links'])[2]")

el3 = driver.find_element_by_xpath("(//a[@class='maxbutton-1 maxbutton maxbutton-download-links'])[3]")

then you can extract element href/link attribute like that:

link = el.get_attribute('href')

or click it like that:

el.click()

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