Okay, Swetha, the problem seems to be that there is an animation, the webpage is changing all the while and that element even though it’s the same element before and after waiting, if you are too quick, no dice. It looks like there are 2 ways
Basically there are 2 options open to us , wait for the page to stop “loading”
chrome_wd = webdriver.Chrome(ChromeDriverManager().install())
element = WebDriverWait(chrome_wd, 20).until(EC.presence_of_element_located(
chrome_wd.execute_script(“arguments.click();console.log(‘clicked it!!!’);”, element)
# verify dismissed
element = WebDriverWait(chrome_wd, 2).until(EC.presence_of_element_located(
except TimeoutException as e:
print(‘Cookies box is gone’)
personally I would prefer this approach
- wait for button
- click button
- if button still exists goto step 1
with a timeout to prevent hangs of course. That algorithm would feel cleaner to me because it’s very explicit what we are up to.
I am normally raising a bug with the developers to fix any places where any web element that needs automating are not easy to get to (the animation problem is a marketing problem which is a battle I’m not prepared to fight today.) has a unique ID. I’m trying lately to rise these bugs as blockers to force the developers to pro-actively make the app testable before they hand it to QA. It saves a load of time.
(I may be wrong, as I mentioned, not been doing web hacking long, many folk been doing this with a year for every month of my experience.)