0

I'm trying to click in this button but I got an error everytime:

<div class="refresh-box">
        <span>
<button type="button" id="ember1328" class="btn-refresh btn btn-default ember-view"><!---->          <i class="fa fa-refresh fa-2x"></i>
</button>          update: <font class="color-black"> 11/04/2022 23:31:50</font>
        </span>
      </div>

The code that i'm trying to use:

driver.find_element(By.XPATH, '//*[@id="ember581"]/div[2]/div/div[2]/div').click()

Could anyone can help me?

3 Answers 3

1

To identify the ember button you can use either of the following locator.

CSS_SELECTOR:

driver.find_element(By.CSS_SELECTOR, "button.btn-refresh.btn-refresh.btn.btn-default.ember-view[id^='ember']").click()

XPATH:

driver.find_element(By.XPATH, "//button[contains(@class,'btn-refresh') and starts-with(@id,'ember')]").click()

To avoid synchronization issue use WebDriverWait()

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn-refresh[id^='ember']"))).click()

OR

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(@class,'btn-refresh') and starts-with(@id,'ember')]"))).click()

You need following libraries:

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

Comments

0

Code snippet which you have attached and xpath are very different.

driver.find_element(By.id,"ember1328");

try this

<div class="refresh-box">
        <span>
<button type="button" id="ember1328" class="btn-refresh btn btn-default ember-view"><!---->          <i class="fa fa-refresh fa-2x"></i>
</button>          update: <font class="color-black"> 11/04/2022 23:31:50</font>
        </span>
      </div>

Comments

0

The desired element is a Ember.js enabled element and a dynamic element. So everytime you access the application the dynamic part of the value of the id attribute will always get changed. So you have to construct a dynamic


Solution

To click on the <button> element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.refresh-box button.btn-refresh.btn.btn-default.ember-view[id^='ember'] i.fa.fa-refresh.fa-2x"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='refresh-box']//button[@class='btn-refresh btn btn-default ember-view' and starts-with(@id, 'ember')]//i[@class='fa fa-refresh fa-2x']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

Comments

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.