Is it possible request an URL and check for the elements before the page renders? I'm using Python + Selenium.
Asked
Active
Viewed 444 times
2

undetected Selenium
- 183,867
- 41
- 278
- 352

Jarlei Sassi
- 35
- 4
-
Why do you want to check for elements before the page renders? What is your goal? Do you have some `code trials` for us to work off of? – PixelEinstein Jul 19 '18 at 00:27
-
I'm checking an available date in the calendar to book an appointment. There's no reason to load the entire page, just ckeck for the element. – Jarlei Sassi Jul 19 '18 at 10:38
1 Answers
2
A one word answer to your question will be Yes.
Explanation
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?

undetected Selenium
- 183,867
- 41
- 278
- 352