Home > OS >  How to select the non-static elements with non-static ids?
How to select the non-static elements with non-static ids?

Time:06-23

I'm trying to use selenium on Facebook but after each time I start the bot A modal opens and asks for 'Allow the use of cookies from Facebook on this browser?' I want to close the modal by clicking on "Only allow essential cookies" button but whenever I refresh the page, the ID of the button changes.

WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="u_0_l_GM"]'))).click()

The "u_0_l_GM" part. "GM" changes on every refresh

CodePudding user response:

Buddy here you can use the xpath inbuilt function contains you need to change your xpath to this //*[contains(@id,"u_0_l_")]

Hope this works

  • Related