0

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:

pge='https://www.google.com/search?rlz=1C1GCEU_en__835__835&ei=gfW0XKjNFeXjkgW8g6PYDA&q=huawei%20stores%20italy&oq=huawei+stores+italy&gs_l=psy-ab.3..0i22i30l3.4596.6067..6522...1.0..0.99.530.7......0....1..gws-wiz.......0i71j0i20i263j0i67j0j33i160.QYVpoia0BL4&npsic=0&rflfq=1&rlha=0&rllag=45499827,9211657,4837&tbm=lcl&rldimm=17275164572016510107&lqi=ChNodWF3ZWkgc3RvcmVzIGl0YWx5IgOIAQFaDwoNaHVhd2VpIHN0b3Jlcw&ved=2ahUKEwiKrMm8g9PhAhXQ4KQKHY9KDc8QvS4wAXoECAoQHQ&rldoc=1&tbs=lrf:!2m1!1e3!2m1!1e16!3sIAE,lf:1,lf_ui:4#rlfi=hd:;si:17275164572016510107,l,ChNodWF3ZWkgc3RvcmVzIGl0YWx5IgOIAQFaDwoNaHVhd2VpIHN0b3Jlcw;mv:!1m2!1d45.5258666!2d9.274078399999999!2m2!1d45.443338999999995!2d9.1152195;tbs:lrf:!2m1!1e3!2m1!1e16!3sIAE,lf:1,lf_ui:4'

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
tezzaaa
  • 459
  • 1
  • 6
  • 17
  • There are 7 iframes on that page, but I assume the one you want is the first one from the top of the page. If the 'duplicate' answers don't help you, try this: driver.find_element_by_xpath("//*[contains(local-name(), 'iframe')]")[0] – Alichino Apr 17 '19 at 07:45
  • Sorry, should be: < find_elements> - plural. – Alichino Apr 17 '19 at 10:54

0 Answers0