Anees
Anees

Reputation: 19

Automated Chromium Webdriver becomes very slow with Selenium at the end

I am using Python selenium framework with Chrome webdriver(version 3.4.3) to load a webpage multiple times using Chromium web browser 58.0.3029.110 (64-bit) under linux platform=Linux 3.13.0-24-generic x86_64.

It works fine at the beginning. However, after multiple times of loading the web page, the web browser becomes slow to open and then it doesn't open. I feel the system becomes slow as well.

I have two questions here. The main one is how can I keep the chromium browser working fast as the beginning? Secondly, Why when I replace driver.close() with driver.quit() the successive opening of the web broswer takes too much time?

This is my python code

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
import time
Time_Out=60
site="http://www.google.com.au"

def Loading_Webpage(website):
   option = webdriver.ChromeOptions()
   driver = webdriver.Chrome(chrome_options=option, executable_path="/usr/lib/chromium-browser/chromedriver")
   driver.set_page_load_timeout(Time_Out)
   try:
       driver.get(website)
   except TimeoutException:
       return 1
   driver.close()
raw_input('Start Running')
for i in range(500):
    start=time.time()
    Loading_Webpage(site)
    print i, time.time()-start

Upvotes: 1

Views: 2605

Answers (1)

Ron Norris
Ron Norris

Reputation: 2690

I ran this variation of your test on Window 10. Here are my results. The starting of the webdriver varied the most, closely followed by the amount of time to load the page. The driver.quit() time was very constant. There were no memory leaks (no chrome instances hanging around). Obviously, the fastest way to run this is to not quit the driver every time you navigate to a page;)

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
import time
Time_Out=60
site="http://www.google.com.au"

def Loading_Webpage(i, website):
   start = time.time()
   option = webdriver.ChromeOptions()
   driver = webdriver.Chrome(chrome_options=option)
   driver.set_page_load_timeout(Time_Out)
   dstart = time.time() - start
   try:
       driver.get(website)
       dload = time.time() - start - dstart
   except TimeoutException:
       return 1
   driver.quit()
   dquit = time.time() - start - dstart - dload
   all = time.time() - start
   print(i, dstart, dload, dquit, all)

for i in range(500):
    Loading_Webpage(i, site)

Upvotes: 2

Related Questions