0

This is my code to load website via Firefox with selenium.

This is my code:

from selenium import webdriver
import datetime

firefox_driver = r'D:\Downloads\geckodriver-v0.30.0-win64\geckodriver.exe'
print(datetime.datetime.now())
firefox_user_data = r'C:\\Users\\Saeed\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\gbcf38v6.default-release-2'
print(datetime.datetime.now())
options = webdriver.FirefoxOptions()
print(datetime.datetime.now())
options.add_argument(f'--user-data-dir={firefox_user_data}')
print(datetime.datetime.now())
options.add_argument('--profile-directory=gbcf38v6.default-release-2')
print(datetime.datetime.now())
driver = webdriver.Firefox(executable_path=firefox_driver, firefox_profile=firefox_user_data)
print(datetime.datetime.now())
driver.get('https://google.com')
print(datetime.datetime.now())
driver.quit()

This is the log:

2022-04-05 14:08:39.171385
2022-04-05 14:08:39.171385
2022-04-05 14:08:39.171385
2022-04-05 14:08:39.171385
2022-04-05 14:08:39.171385
C:\Users\Saeed\Desktop\python-projects\test.py:24: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver = webdriver.Firefox(executable_path=firefox_driver, firefox_profile=firefox_user_data)
C:\Users\Saeed\Desktop\python-projects\test.py:24: DeprecationWarning: firefox_profile has been deprecated, please pass in an Options object
  driver = webdriver.Firefox(executable_path=firefox_driver, firefox_profile=firefox_user_data)
2022-04-05 14:10:33.400797
2022-04-05 14:10:39.929654

It takes around 2 minutes to load, while if I change my code to this:

...
driver = webdriver.Firefox(executable_path=firefox_driver)
...

it only takes around 6 seconds to load Firefox.

The question is why it's taking too much to load while loading profile?

Saeed
  • 3,255
  • 4
  • 17
  • 36
  • 1
    Regarding query 1: It is not clear if the profile is loading late or the browser instance itself is taking time to load up. If it is the profile, then there is nothing to do from the webdriver end. – Anand Gautam Apr 05 '22 at 13:47
  • @AnandGautam I removed the first question (I found it's only a warning, so nothing to worry about). – Saeed Apr 06 '22 at 08:03

1 Answers1

0

Regarding query 2: executable_path has been deprecated and service is introduced in latest Selenium. You may use service object from Service class as below:

from selenium.webdriver.firefox.service import Service
executable_path = 'Your gecko_driver file path'
s = Service(executable_path)
driver = webdriver.Firefox(service=s)

Note that what you get is a deprecated warning, which means your code would still run until the executable_path is supported; however, it is better if you update with service.

You may find more about service in the below links:

link_1

previous SO query

Anand Gautam
  • 2,018
  • 1
  • 3
  • 8
  • Thanks, when I remove `firefox_profile`, it loads only 6 seconds now to load (it's normal). But the issue is I do not have the profile (I mean cache and cookies). I need it. How to have and load that? – Saeed Apr 06 '22 at 08:01