Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Improving loading time of webpage in python via selenium

How to reduce time of explicit wait of a page with full of AJAX statements?
wait=WebDriverWait(driver,timeout=77) gives an exact results of located elements that I need, but consumed time is huge. When I set timeout time to lower than 70 the webdriver can not locate elements gives unable to locate elements.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

There are some web pages having some JavaScripts there, making those pages loading long time.
Selenium has 3 possible settings for the Page loading Strategy. The default strategy is normal. With this setting Selenium will wait for complete document readiness state of the loaded page. To reduce the loading time with Selenium we normally use eager strategy setting. This will wait for interactive document readiness state of the loaded page.
Here some simple working example of how to set page strategy to eager with Selenium on Python:

from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument("start-maximized")

caps = DesiredCapabilities().CHROME
caps["pageLoadStrategy"] = "eager"

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(service=webdriver_service, options=options, desired_capabilities=caps)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading