1

I have this button on the page:

<button type="submit" class="sc-pjTqr dzmlqP">Continue</button>`

I checked the documentation and StackOverflow answers and it seems to me that the solution should be:

continue = driver.find_element(By.CSS_SELECTOR,"button.sc-pjTqr.dzmlqP")

But does not work.

I searched for solutions, but I didn't understand. Why?

3
  • Can you confirm the URL? Commented Jul 23, 2022 at 17:54
  • What do you mean? Commented Jul 23, 2022 at 18:01
  • The url where this button can be found. Commented Jul 23, 2022 at 18:02

2 Answers 2

2

The classnames i.e. sc-pjTqr, dzmlqP are dynamically generated and is bound to chage sooner/later. They may change next time you access the application afresh or even while next application startup. So can't be used in locators.


Solution

To identify the element with text as Continue you can use the following locator strategy:

  • Using xpath:

    continue = driver.find_element(By.XPATH, "//button[text()='Continue']")
    

Ideally to identify the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following locator strategy:

  • Using XPATH:

    continue = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Continue']")))
    
  • 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
    
Sign up to request clarification or add additional context in comments.

Comments

0

The OP doesn't confirm the url where this button lives, so I can test the solution:

button = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, "sc-pjTqr")))

There are other ways as well.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.