0

I am not able to click on a Button(Save) on Selenium webdriver in BDD Framework.

I am able to click in general script but when I execute same script through BDD Framework it doesn't work, please help me on this.

<button data-id="save-button" aria-label="Save" type="button" class="inline-flex items-center font-bold border rounded transition duration-300 ease-out hover:bg-primary-700 active:bg-primary-800 bg-primary-600 button-normal text-white justify-center text-base border-primary-600 px-4" style="background-image: linear-gradient(rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0));">Save</button>

I have tried with below codes:

element = self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/div[1]/div/div[2]/div[2]/button[2]")
        self.driver.execute_script("arguments[0].click();", element)

element = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable(By.XPATH, "//button[text()='Clear all changes']/following::button[@data-id='save-button']")).click()
        self.driver.execute_script("arguments[0].click();", element)

self.driver.find_element_by_xpath("/html/body/div[1]/div/div/div/div[1]/div/div[2]/div[2]/button[2]").click()

actions.click(self.driver.find_element_by_xpath("/html/body/div[1]/div/div/div/div[1]/div/div[2]/div[2]/button[2]")).perform()
        actions.move_to_element(button).click(button).perform()

self.driver.find_element_by_class_name('inline-flex items-center font-bold border rounded transition duration-300 ease-out hover:bg-primary-700 active:bg-primary-800 bg-primary-600 button-normal text-white justify-center text-base border-primary-600 px-4').click()

ele =self.driver.find_element_by_css_selector("button[data-id='save-button']").click()
        ele.click()

I have wasted more than two days on this button. The same element works with normal script execution without using any frame work.

Working script below:

self.driver.find_element_by_xpath("/html/body/div[1]/div/div/div/div[1]/div/div[2]/div[2]/button[2]").click()

Thanks in advance.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

To click on a clickable 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(self.driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[data-id='save-button'][aria-label='Save']"))).click()
    
  • Using XPATH:

    WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@data-id='save-button' and @aria-label='Save'][text()='Save']"))).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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352