I'm a bit stuck, I've been trying to scroll down a web page using python and selenium. The problem is there seems to be a iframe. I did a bit of research and somehow I'm able to kind of detect the iframe but unable to activate it:
SCROLL_PAUSE_TIME = 2
CYCLES=10
browser = webdriver.Firefox(firefox_options=opt)
browser.get(pge)
comment_button = browser.find_elements_by_class_name('Ob2kfd')
sleep(5)
print("clicking on on link")
comment_button[0].click()
sleep(2)
html = browser.find_element_by_tag_name('html')
# This does not work unfortunately:
# frames = browser.find_element_by_tag_name('iframe')
# browser.switch_to.frame(frames)
for i in range(CYCLES):
html.send_keys(Keys.DOWN)
time.sleep(SCROLL_PAUSE_TIME)
When i execute the above code, I can see the scroll down happening in the window in the background as opposed to the front pop up window...
if anyone could pse help it would be much appreciated... I tried a lot of things like using the console and web extentions addons to find the iframe but no luck and i'm really stuck :-(
Best Wishes
UPDATE: Hi Again, some of you suggested this question as a duplicate, but when i try the duplicate solution it does not work (I had tried before posting actually, and I had posted it in my original code also).
SCROLL_PAUSE_TIME = 2
CYCLES=10
browser = webdriver.Firefox(firefox_options=opt)
browser.get(pge)
comment_button = browser.find_elements_by_class_name('Ob2kfd')
sleep(5)
print("clicking on on link")
comment_button[0].click()
sleep(2)
html = browser.find_element_by_tag_name('html')
# This does not work unfortunately:
# frames = browser.find_element_by_tag_name('iframe')
# browser.switch_to.frame(frames)
frames = browser.find_element_by_tag_name('iframe')
browser.switch_to.frame(0)
for i in range(CYCLES):
html.send_keys(Keys.DOWN)
time.sleep(SCROLL_PAUSE_TIME)
I get the following error:
StaleElementReferenceException: Message: stale element reference: element is not attached to the page document