What does #document mean?
Asked Answered
O

2

23

This is the HTML file I have. I am trying to use Selenium-Webdriver API along with ChromeDriver to send_keys to an input filed inside the <body>. But I can't access anything which is inside of #document. I cannot figure out why. Can someone please tell me what this #document means and how can I access any of the elements inside this using Selenium.

<html>
<head>…<head>
<frameset >
    <frame>...</frame>
            <frame name="mainFrame" src>
                #document
                    <html>
                      <head>…</head>
                      <body>…</body>
                    </html>
        </frame>
    </frameset>
</frameset>

This is a router webpage, the actual webpage is HUGE, so I haven't pasted it here.

The router webpage

Overbear answered 31/1, 2014 at 7:25 Comment(6)
I would ideally want to know how to access elements inside this #document. I have tried the traditional ways using find_elements_by_xxx but haven't got any result. I would also like to know what #document means, because I couldn't get an answer by Googling it.Overbear
Ok, thanks @user2864740. I just added screenshot to my original post. If you see that, the actual HTML I need to use is sitting inside #document. @user1177636 I have tried, switching frames and to default_content, etc.. nothing has helped. I can't find these elements even from the Chrome dev tool console when I use commands like document.getElementsbyName(''). Seems like everything under #document is invisible.Overbear
@Overbear That's a "virtual element". It's a Chrome-specific way of indicating that it is part of a different (embedded) DOM - you cannot use or query it (because the "virtual element" does not exist as part of the DOM) from code.Aggy
@Overbear So don't look for "#document", but look for the task, such as "selenium frames" - #15465308 , #6061057 YMMVAggy
@user2864740, thanks, it worked. I have put the code below, just for future reference. Here since there are multiple frames we have to switch to the default content and then move to the frame of our choice. driver.switch_to_default_content() frame =driver.find_element_by_name('mainFrame') driver.switch_to_frame(frame) elem = driver.find_element_by_xpath('//input[@name="ui_pws"]')Overbear
@Overbear Cool, glad you found a solution. Put your solution into an answer and then accept it later when you can. That will help most - and be easier to see!Aggy
O
21

Just to summarize on what I learnt and implemented.

  1. #document is a virtual element, which doesn't really mean anything.

  2. If you have mulitple frames/framesets, you will have to switch frames.

    a. so first get to the default content. driver.switch_to_default_content()

    b. then get to the frame that you want to work with. frame = driver.find_element_by_name('mainFrame')

  3. Then play with the elements in that frame.

Overbear answered 31/1, 2014 at 9:13 Comment(2)
This must be what is meant by driver: cycle.js.org/drivers.htmlSchreibe
selenium-python.readthedocs.io/…Department
T
0

I have tried to do the same process in C#, and this worked for me. (I leave the code here for someone who maybe is looking at this in C#). I hope this will be useful for someone!

var FrameName = driver.FindElement(By.Name("...Frame Name..."));    
driver.SwitchTo().Frame(FrameName);    
var elem = driver.FindElement(By.XPath("... Xpath from in of the 
        Frame..."));    
elem.Click();
Toffeenosed answered 14/3, 2022 at 11:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.