Is it possible request an URL and check for the elements before the page renders? I'm using Python + Selenium.
A one word answer to your question will be Yes.
Generally each WebElement on a webpage have 3 (three) distinct states as follows:
presence
: Element is present on the DOM of a page.visibility
: Element is present on the DOM of a page and visible.interactable
(i.e. clickable
): Element is visible and enabled such that you can click it.When Selenium loads a webpage/url by default it follows a default configuration of pageLoadStrategy
set to normal
. You can opt not to wait for the complete page load. So to avoid waiting for the full webpage to load you can configure the pageLoadStrategy
. pageLoadStrategy
supports 3 different values as follows:
normal
(complete page load)eager
(interactive)none
Here is a sample code block to configure the pageLoadStrategy
:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities().FIREFOX.copy()
caps["pageLoadStrategy"] = "none"
driver = webdriver.Firefox(desired_capabilities=caps, executable_path=r'C:\path\to\geckodriver.exe')
driver.get("http://google.com")
You can find a detailed discussion in How to make Selenium not wait till full page load, which has a slow script?