问题
I have recently been trying to get a Selenium environment up and running again. Everything works as it should with scripts executing as they should, using different web drivers etc etc.
However, the initial launch of each driver takes anywhere between 2-5 min to launch. This makes it a pain to develop and troubleshoot my scripts.
I use Python 3.6 with PyCharm and Selenium installed with pip. The same issue is present with Python 2.7.
Things I have tried so far (without success):
- Reinstalled Python
- Reinstalled Selenium
- Run the script through PyCharm and via a terminal
- Replaced the web drivers with earlier and later versions.
- Disabled proxy and javascript for the web drivers
Here is what I am running. This simple script takes up to 5min to run, but works correctly and returns no warnings or errors.
from selenium import webdriver
import time
print(time.localtime())
browser = webdriver.Firefox()
browser.get('http://seleniumhq.org/')
print(time.localtime())
EDIT: A single run of the code above yields the following geckodriver.log
1528112695159 geckodriver INFO geckodriver 0.19.1
1528112695168 geckodriver INFO Listening on 127.0.0.1:3148
1528112747876 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\victorsk\\AppData\\Local\\Temp\\rust_mozprofile.ULuflXGoq9rE"
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
1528112791808 Marionette INFO Listening on port 3158
1528112792599 Marionette WARN TLS certificate errors will be ignored for this session
[Parent 36664, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Parent 36664, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 22672, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 22672, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/sr[Parent 36664, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 25068, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 25068, C*** UTM:SVC TimerManager:registerTimer called after profile-before-change notification. Ignoring timer registration for id: telemetry_modules_ping
回答1:
These error messages...
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
...implies that there were several attempts to read the existing VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
.
Your main issue is the presence of os chores within your system.
- Your Selenium Client version is unknown to us.
- Your GeckoDriver version is v0.19.1.
- Your Firefox version is unknown to us.
Solution
To speed up the operation follow the steps:
- Upgrade Selenium to current levels Version 3.12.0.
- Upgrade GeckoDriver to GeckoDriver v0.20.1 level.
- Ensure GeckoDriver binary is present in the specified location.
- Ensure GeckoDriver is having executable permission for non-root users.
- Upgrade Firefox version to Firefox v60.0.1 levels.
- Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
- Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
- If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
- Take a System Reboot.
- Execute your
Test
as a non-root user. - Always invoke
driver.quit()
withintearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.
Note: Do not disable JavaScript. Disabling JavaScript might lead to a incomplete loading of the webpage as all the web designers/developers believes JavaScript is available in every browser and all the recent browser features and effects are implemented using JavaScript.
来源:https://stackoverflow.com/questions/50679623/selenium-geckodriver-is-slow-to-launch-firefox-browser