From this link, I assume the DOM should be loaded as a whole at first in RAM.
How DOM works/is loaded? (in HTML)
But then I test in Selenium with a timeout e
I found the answer by checking the loading behavior of HTML.
Basically the HTML loads upside down, that said, I just have to check if a elemet behind the elemt, e.g. if another element comes after , just check if another element is presented or not. If yes, then all the elements must be loaded.
As per your code trials you are using ChromeDriver and Chrome Browser to Automate the steps. As you have configured set_page_load_timeout(10)
the timeout exception is raised as the page havn't completely loaded within the timeframe configured through set_page_load_timeout()
. But as you have invoked print(self.page_source)
the elements rendered within the partially rendered HTML DOM are retrieved.
Now about your individual queries :
How can I make sure some elements are already loaded?
: An ideal testcase would have a definite step e.g. to validate the presence of an element, to validate the visibility of an element or to validate the interactability (while clicking) of element. From this perspective verifying the elements are already loaded may not include the desired element. Hence instead of such a broader search criteria you need to narrow down your search criteria to some thing definite e.g.
Implementing these narrowed down search criteria can save a lot of execution time with the help of WebDriverWait inconjunction with expected_conditions.
How can I make sure all elements are loaded?
: Again, our tests should be focused only on the element/elements with which we need to interact with and leaveout verifying the status/condition of other elements which are not of our interest.
Now, following the two points mentioned above these are the 3 most commonly used usecases :
As per the usecase you mentioned you can make a List of all the <th>
elements visible within the DOM Tree whilst waiting for a configurable amount of time inducing WebDriverWait as follows :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
headerList = WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//table[@class='fth1_' and @id='fth1_']/thead/tr//th")))
Note : The xpath used in this illustration is a sample xpath used only for demonstration purpose.