2 download click button with same class using selenium python

Viewed 30

I am unable to click on 2 download buttons with same button class. below is the code

file=driver.find_element_by_xpath("(//button[@class='MuiButtonBase-root MuiIconButton-root IconButton-sc-iv40hv-1 cLszZl IconButton-sc-iv40hv-0 hbJxSM DownloadButton-sc-19l7ggt-0 gHtfyl MuiIconButton-colorPrimary'])")


driver.execute_script("arguments[0].click();", file)

this works only for 1st button..

2nd button if add 2nd file with index val 2... only second button works

I need to click on both download buttons one after another..

1 Answers

To get the specific button try with class and index OR try with text and index whichever you comfortable.

Example you have 2 buttons like this

Button 1 :

<button class="expedition_button awesome-button " onclick="attack(null, '2', 1, 0, '')">Attack</button>

Button 2 :

<button class="expedition_button awesome-button " onclick="attack(null, '2', 2, 0, '')">Attack</button>

you can finish with this

driver.find_element_by_xpath("(//button[text()[contains(.,'Attack')]])[indexval]") 
driver.find_element_by_xpath("(//button[@class='expedition_button awesome-button '])[indexval]")

And then Similar for Button 2 , 3 & 4 just increase the index value.

For Button1:

driver.find_element_by_xpath("(//button[text()[contains(.,'Attack')]])[1]")

OR

driver.find_element_by_xpath("(//button[@class='expedition_button awesome-button '])[1]")
Related