0

I tried using both xpath and classname to locate and click the button. However, nothing is working.

driver.find_element(By.XPATH, "//button[@class='sc-cqCuEk ffSPoi MuiButtonBase-root sc-dliRfk hLpdQI MuiAccordionSummary-root Mui-expanded MuiAccordionSummary-gutters sc-kAKrxA ALFEK']").click()

button class="sc-cqCuEk ffSPoi MuiButtonBase-root sc-iqzUVk gChJxn MuiIconButton-root MuiIconButton-sizeLarge sc-dhVevo eheiFN" tabindex="0" type="button">svg class="sc-eMigcr kvMRMj MuiSvgIcon-root MuiSvgIcon-fontSizeMedium sc-BOulX fmYgpR" focusable="false" aria- hidden="true" viewBox="0 0 24 24" data-testid="KeyboardArrowUpIcon">path d="M7.41 15.41 12 10.83l4.59 4.58L18 14l-6-6-6 6z">

svg class="sc-eMigcr kvMRMj MuiSvgIcon-root MuiSvgIcon-fontSizeMedium sc-BOulX fmYgpR" focusable="false" aria-hidden="true" viewBox="0 0 24 24" data- testid="KeyboardArrowUpIcon"> /path>

5
  • Post your code, what have you tried until now? Post the url as well. Commented Jul 26, 2022 at 12:39
  • Please provide enough code so others can better understand or reproduce the problem. Commented Jul 26, 2022 at 12:40
  • @platipus_on_fire_333 Please check now Commented Jul 26, 2022 at 13:04
  • What is the url you are accessing? Commented Jul 26, 2022 at 13:22
  • @platipus_on_fire_333 It is a company url that requires login Commented Jul 26, 2022 at 13:24

1 Answer 1

0

Try locating and clicking it with

WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "sc-cqCuEk.ffSPoi.MuiButtonBase-root.sc-iqzUVk.gChJxn.MuiIconButton-root.MuiIconButton-sizeLarge.sc-dhVevo.eheiFN"))).click()

You will also need the following imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time as t

EDIT: In the unlikely scenario in which you have absolutely identical X number of buttons and you want to click all of them (?!?!), you can do something like this:

buttons = WebDriverWait(browser, 20).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "sc-cqCuEk.ffSPoi.MuiButtonBase-root.sc-iqzUVk.gChJxn.MuiIconButton-root.MuiIconButton-sizeLarge.sc-dhVevo.eheiFN")))
for button in buttons:
    button.click()
    t.sleep(0.5)
Sign up to request clarification or add additional context in comments.

3 Comments

so all the buttons on this page have the same class name. how can i click all of them?
You find a differential between them. If they are absolutely identical, you use something like buttons = WebDriverWait(browser, 20).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".. whatever that is--"))) and iterate through them, and click each of them.
Can you please provide a sample code to iterate all of them?

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.