'how do i "Factory Reset Runtime" in google Collaboratory using selenium Python?

I'm trying to do some automation with Google colab for personal use and testing. I'm stuck at one point where I'm not able to find any way out.

I want to factory reset google colab using selenium python. The code below is the closest I could get... I even tried WebdriverWait but that too couldn't find the second element in the dropdown.

To recreate this scenario, open any notebook in google colab, go to "Runtime" > "Factory Reset Runtime"

Any solution ??

Edit : I did not get what it was suggested by user undetected selenium (which i m using btw to bypass google authentication issue) but here are the elements which i do get when I copy.

copy element : <div class="goog-menuitem-content" style="user-select: none;"><!--?lit$6536785333$-->Factory reset runtime</div>

copy XPATH : //*[@id=":26"]/div

copy Selector : #\:26 > div

The tag i mentioned below is dynamic XPATH. I tried all i mentioned here. But no success. I dont know what am i doing wrong.

> driver.find_element(By.CSS_SELECTOR, "#runtime-menu-button .goog-menu-button-caption").click()
> sleep(1)
> driver.find_element((By.XPATH, "//div\[contains(text(),'Factory reset runtime')\]")).click()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source