SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.53k stars 8.16k forks source link

Firefox WebDriver start is very slow #8407

Closed CRYPTO-7CA closed 4 years ago

CRYPTO-7CA commented 4 years ago

🐛 Bug Report

The part of "webdriver.Firefox" command takes very long time to start (1 whole minute or so) whereas Chrome starts pretty much instantly.

To Reproduce

I provided a minimalistic Python code, which alone is enough to reproduce the problem (scroll down to the "Test script" section for reference). This problem was encountered on 2 separate machines (each being a different user).

Detailed steps to reproduce the behavior:

  1. Meet all preconditions (Have python 3 installed, have python pip installed, install with python pip the "selenium" package)
  2. Paste the provided Python code in a new python script file
  3. Execute this python script file

Expected behavior

The Firefox web browser (computer controlled) opens pretty much instantly after executing the python script.

Test script or set of commands reproducing this issue

from selenium import webdriver
import time

# The argument "C:\\Program Files\\Python37" assumes, that this is the location of the 'geckodriver.exe'
webdriver_instance_1 = webdriver.Firefox("C:\\Program Files\\Python37")
webdriver_instance_1.maximize_window()
webdriver_instance_1.implicitly_wait(10)
webdriver_instance_1.get('https://github.com/seleniumhq')

time.sleep(3)
sign_in = webdriver_instance_1.find_element_by_xpath('/html/body/div[1]/header/div/div[2]/div[2]/a[1]')
sign_in.click()
time.sleep(3)
webdriver_instance_1.quit()

print('Done!')

Environment

OS: Windows 10 Browser: Mozilla Firefox Browser version: 77.0.1 (64-bit) Browser Driver version: geckodriver 0.26.0 (e9783a644016 2019-10-10 13:38 +0000) Language Bindings version: Python 3.7

This bug was reported here before - https://github.com/seleniumhq/selenium/issues/2441#issue-164619948

That's pretty much it. Is any more information required?

AutomatedTester commented 4 years ago

I have tried to create the issue and can't. I tweaked the script slightly

from selenium import webdriver
import time

import datetime
start = datetime.datetime.now()
webdriver_instance_1 = webdriver.Firefox()
finish = datetime.datetime.now()
print(finish - start)
webdriver_instance_1.maximize_window()
webdriver_instance_1.implicitly_wait(10)
webdriver_instance_1.get('https://github.com/seleniumhq')

time.sleep(3)
sign_in = webdriver_instance_1.find_element_by_xpath('/html/body/div[1]/header/div/div[2]/div[2]/a[1]')
sign_in.click()
time.sleep(3)
webdriver_instance_1.quit()

print('Done!')

and get

davidburns in ~/development/selenium on master ● λ export PATH=/Users/davidburns/development/selenium-binaries:$PATH
davidburns in ~/development/selenium on master ● λ python issue8407.py
0:00:06.087235
/Users/davidburns/.pyenv/versions/3.8.2/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py:430: UserWarning: find_element_by_* commands are deprecated. Please use find_element() instead
  warnings.warn("find_element_by_* commands are deprecated. Please use find_element() instead")
Done!
davidburns in ~/development/selenium on master ● λ python issue8407.py
0:00:02.605558
/Users/davidburns/.pyenv/versions/3.8.2/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py:430: UserWarning: find_element_by_* commands are deprecated. Please use find_element() instead
  warnings.warn("find_element_by_* commands are deprecated. Please use find_element() instead")
Done!
davidburns in ~/development/selenium on master ● λ python issue8407.py
0:00:03.407212
/Users/davidburns/.pyenv/versions/3.8.2/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py:430: UserWarning: find_element_by_* commands are deprecated. Please use find_element() instead
  warnings.warn("find_element_by_* commands are deprecated. Please use find_element() instead")
Done!

Could you investigate where the slowdown could be?

CRYPTO-7CA commented 4 years ago

Hello AutomatedTester

Thanks for the swift response. I have just tested your tweaked script on my end and I see, that it takes 5-6 seconds now, which is a huge improvement.

F:\Testing\mpa1000\python\autotests_selenium>python test.py
0:00:05.775317
Done!

F:\Testing\mpa1000\python\autotests_selenium>python test.py
0:00:05.168924
Done!

F:\Testing\mpa1000\python\autotests_selenium>python test.py
0:00:05.180766
Done!

F:\Testing\mpa1000\python\autotests_selenium>

I noticed, that the biggest difference is in this one code webdriver_instance_1 = webdriver.Firefox() where the path to the geckodriver is absent. Initially i provided that parameter in accordance to the Selenium Python course (as instructed on udemy.com).

In a way this is a bug when providing that parameter inside webdriver.Firefox() but this bug does not reproduce with Chrome webdriver webdriver.Chrome('C:\\Program Files\\Python37\\chromedriver.exe')