0

i was trying various "find element by" methods to find a button that i need to click

<button data-test-modal-close-btn aria-label="Dismiss" id="ember1106" class="artdeco-modal__dismiss artdeco-button artdeco-button--circle artdeco-button--muted artdeco-button--2 artdeco-button--tertiary ember-view">flex

The html code has been mentioned above

and i tried access it through id but the ember under the id will randomly shuffles it number each time. so i red a answer on internet that i can use xpath to find aria label

close_button = self.driver.find_elements_by_css_selector("[aria-label=Dismiss]")
close_button.click()

but its helpless. can someone help me on this

1
  • What is the error ? Commented Aug 20, 2021 at 13:58

2 Answers 2

1

Your css selector is wrong basically you are missing button, try below code :

close_button = self.driver.find_elements_by_css_selector("button[aria-label=Dismiss]")
close_button[0].click()

also since you have mentioned ember1106 is dynamically, generated

the below css may help you :-

button[id^='ember']

also you can try this :

button[aria-label='Dismiss'][class*='dismiss']

also try with explicit wait :-

wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[aria-label=Dismiss]"))).click()

imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Sign up to request clarification or add additional context in comments.

1 Comment

explict wait worked well. thanks for the help
1

Your locator is wrong, it should be button[aria-label=Dismiss].
Also, you should use find_element_by_css_selector, not find_elements_by_css_selector.
Since find_elements_by_css_selector returns a list of web elements, not a single element you can click directly.
So, your code can be

close_button = self.driver.find_element_by_css_selector("button[aria-label=Dismiss]")
close_button.click()

or

close_button = self.driver.find_elements_by_css_selector("button[aria-label=Dismiss]")[0]
close_button.click()

2 Comments

i got a error trying both of them saying that Message: element click intercepted: Element <div id="ember907" class="full-width artdeco-entity-lockup__title ember-view">...</div> is not clickable at point (258, 591). Other element would receive the click: <div aria-hidden="false" id="ember1029" class="artdeco-modal-overlay artdeco-modal-overlay--layer-default artdeco-modal-overlay--is-top-layer ember-view">...</div>
but the problem has been solved by using the line(wait = WebDriverWait(driver, 10) wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[aria-label=Dismiss]"))).click()). Thanks for the help

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.