0

I am trying to scrape an html table which has two frames. When switching to the first one, the code works well but when switching to default and then to the second frame, I can´t get the full html code.

driver = webdriver.Chrome('/Users/Administrador/Documents/chromedriver')
main_url = 'https://www.justiciacordoba.gob.ar/Estatico/JEL/Escrutinios/ReportesEleccion20190512/default.html'
driver.get(main_url)

#This works fine:

driver.switch_to.frame("topFrame")

# This doesnt:

driver.switch_to.default_content()
driver.switch_to.frame('mainFrame')

page = driver.page_source
page

Output:

'<html><head></head><body></body></html>'
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Please don't change the question based on which you have received well researched answers. Once you receive canonical answers changing the question can make all the existing answers invalid and may not be useful to future readers. If your requirement have changed feel free to raise a new question. StackOverflow contributors will be happy to help you out. For the time being I have reverted back the question to it's initial state. – undetected Selenium May 18 '20 at 22:56

2 Answers2

0

That is the full page!

<frame src="about:blank" name="mainFrame" align="center">
    #document
    <html>
        <head></head>
        <body></body>
    </html>
</frame>

Click with the right mouse button, select "inspect" or "inspect element", and you'll see in the Elements tab of the Development window that that is all the frame has.

In Chrome, you can also press Ctrl+Shift+I and you'll get directly to this tab.

Joao_Augusto
  • 46
  • 1
  • 4
0

Seems you are seeing the right behavior. When the WebDriver's focus is within the <frame> with name as topFrame, unless you select values from the <select> elements and initiate a search, the elements within the <frame> with name as mainFrame aren't redendered. Hence you see the following behaviour:

  • Code Block:

    driver.get('https://www.justiciacordoba.gob.ar/Estatico/JEL/Escrutinios/ReportesEleccion20190512/default.html')
    driver.switch_to.frame("topFrame")
    driver.switch_to.default_content()
    driver.switch_to.frame('mainFrame')
    print(driver.page_source)
    
  • Console Output:

    <html><head></head><body></body></html>
    

In this case if you still want to extract the full HTML from the Top Level Content you can switch to the default_content() as follows:

  • Code Block:

    driver.get('https://www.justiciacordoba.gob.ar/Estatico/JEL/Escrutinios/ReportesEleccion20190512/default.html')
    driver.switch_to.frame("topFrame")
    driver.switch_to.default_content()
    driver.switch_to.frame('mainFrame')
    print(driver.page_source)
    driver.switch_to.default_content()
    print(driver.page_source)
    
  • Console Output:

    <html><head></head><body></body></html>
    <html><head></head><frameset rows="190,*" cols="*" framespacing="0" frameborder="NO" border="0" id="fset">
        <frame src="Index.html" name="topFrame" scrolling="NO" cd_frame_id_="887435be8ea834d3aec3a905bb2f8019">
        <frame src="about:blank" name="mainFrame" align="center" cd_frame_id_="a1abd873a60c8db45dc83e5334321cbc">
    </frameset><noframes></noframes>
    
    </html>
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Hello! Thanks a lot for the answer. I have edited the original post were you can see what I am actually trying to do. I am trying to extract values from the table that is within the mainFrame, but I cant. I though this was due to an error when switching between frames but maybe this is not where the mistake is. What do you think? – Emilio Chambouleyron May 18 '20 at 21:51
  • @EmilioChambouleyron Please reread the answer once again. I have specifically mentioned _When the WebDriver's focus is within the with name as topFrame, unless you select values from the – undetected Selenium May 18 '20 at 22:03
  • Ok, I see. I did in fact initiate a search. I 've edited the original post so that you can see. – Emilio Chambouleyron May 18 '20 at 22:13
  • @EmilioChambouleyron That is a different question all together. I'm afraid, ideally you should raise a new question for your new requirement. – undetected Selenium May 18 '20 at 22:54