Home > Mobile >  Click on ember button selenium python
Click on ember button selenium python

Time:04-13

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

<div >
        <span>
<button type="button" id="ember1328" ><!---->          <i ></i>
</button>          update: <font > 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?

Thank you

CodePudding user response:

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

CodePudding user response:

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

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

try this

<div >
        <span>
<button type="button" id="ember1328" ><!---->          <i ></i>
</button>          update: <font > 11/04/2022 23:31:50</font>
        </span>
      </div>

  • Related