How do you handle dynamic cookie buttons in Selenium?

Viewed 34

I'm trying to click the 'Allow essential and optional cookies button' which pops up on Facebook.


button = driver.find_element(By.XPATH,"//button[@id='u_0_e_EQ']")
button.click

the error is that the id (u_0_e_EQ) changes every time the page is reloaded. Is there any way to get around this?

1 Answers

If the button label is unique, you can use it.

driver.find_element(By.XPATH,"//button[text()='button_label']").click
Related