Python Forum
Migrating Selenium from Windows 7 to 10
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Migrating Selenium from Windows 7 to 10
#1
I am a bit confused about my migration problem. Some Selenium libraries have been deprecated but I cannot figure out how to make the appropriate changes. I apparently have to use 'Service' rather than 'Options' and 'executable_path'. My imports need to be different. Unfortunately reading the documentation I do not see how to specify the location of Firefox and geckodriver. Here is my relevant code segments that works under Windows 7:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
This is where I get errors (correction to line 2 I was able to figure out). Line 3 & 4 is where I get the deprecated error.
options=Options()
options.add_argument("--headless")
options.binary=FirefoxBinary(r'C:\Program Files\Mozilla Firefox\firefox.exe')
browser=webdriver.Firefox(executable_path=r'C:Program Files\Mozilla Firefox\geckodriver.exe',options=options)
Can someone help me convert this code for Windows 10? TIA
Reply
#2
You have to search for upgrade they made in Selenium v4, eg link | tag_upgrade
Here are test upgrade i made for Selenium v4.
It will by similar for FireFox driver.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time

#--| Setup
options = Options()
options.add_argument("--headless")
options.add_argument("window-size=1024,960")
# New
ser = Service(r"C:\cmder\bin\chromedriver.exe")
browser = webdriver.Chrome(service=ser, options=options)
# Old
#browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe', options=options)
#--| Parse or automation
browser.get("https://bors.e24.no/#!/instrument/PCIB.OSE/orderdepth")
time.sleep(2)
# New
volum = browser.find_element(By.CSS_SELECTOR, 'td.number.BIDVOL.number-left')
# Old
#volum = browser.find_elements_by_css_selector('td.number.BIDVOL.number-left')
print(volum.text)
Output:
2 000
Reply
#3
Thanks for the reply. Is the implication that I don't have to specify the path for Firefox (or in your case Chrome)? In any case I am getting this error:

Error:
Traceback (most recent call last): File "C:\Users\dap1\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\common\service.py", line 71, in start self.process = subprocess.Popen(cmd, env=self.env, File "C:\Program Files\Python310\lib\subprocess.py", line 966, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Program Files\Python310\lib\subprocess.py", line 1435, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, FileNotFoundError: [WinError 2] The system cannot find the file specified
I take it that a piece of Selenium has not been installed but I have not been able to find what to install.
Yoriz write Apr-07-2022, 03:46 PM:
Please post errors (In their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#4
Here a working version for Firefox.
So remember that that geckodriver.exe or chromedriver.exe most be in environment variables Path.
I preferer to set path to driver files myself(cmder\bin folder is in my Windows Path) as shown in my code.
You can use webdriver_manager the set this driver and Path automatically.
Then is usage line 15 in my code.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.by import By
import time

#--| Setup
options = Options()
options.add_argument("--headless")
options.add_argument("window-size=1024,960")
# New
ser = Service(r"C:\cmder\bin\geckodriver.exe")
browser = webdriver.Firefox(service=ser, options=options)
# pip install webdriver-manager
#browser = webdriver.Firefox(service=Service(GeckoDriverManager().install()))
#--| Parse or automation
browser.get("https://bors.e24.no/#!/instrument/PCIB.OSE/orderdepth")
time.sleep(2)
# New
volum = browser.find_element(By.CSS_SELECTOR, 'td.number.BIDVOL.number-left')
# Old
#text_type = browser.find_elements_by_css_selector('td.number.BIDVOL.number-left')
print(volum.text)
Output:
2 150
Reply
#5
Thanks again for the reply. I found this post in stack overflow that never was answered but is exactly my problem.

https://stackoverflow.com/questions/5575...be-missing

The gecko driver is indeed in my path:

>echo %PATH%
C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files\Python310\Scripts\;C:\Program Files\Python310\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Git\cmd;C:\Program Files\Mozilla Firefox;C:\Users\dap1\AppData\Local\Microsoft\WindowsApps;
Reply
#6
Do you still have problem?
(Apr-07-2022, 06:06 PM)gw1500se Wrote: The gecko driver is indeed in my path
You make this bold C:\Program Files\Mozilla Firefox this is placement of FireFox files and executable firefox.exe.
Not geckodriver.exe which you most download and extract(geckodriver.exe) and put in a Windows Path folder that listed eg this folder fine C:\Program Files\Python310\Scripts\
I would not put in FireFox folder,is this clear now?

As i linked to avoid to this manually there is Webdriver Manager for Python
The point of Webdriver Manager is to automate the process,so it download the webdriver and put in Path automatically.
Reply
#7
Yes, I still have the problem. I put the gecko driver in the same directory as FF right from the beginning. I don't know why it can't go in that folder but I will move it and substitute that path per your suggestion.
Reply
#8
No joy. The gecko driver is now in the python scripts directory. Same error.

>echo %PATH%
C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files\Python310\Scripts\;C:\Program Files\Python310\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Git\cmd;C:\Program Files\Python310\Scripts;C:\Users\dap1\AppData\Local\Microsoft\WindowsApps;
Reply
#9
(Apr-08-2022, 03:28 PM)gw1500se Wrote: ;C:\Program Files\Python310\Scripts
This is wrong in your Path missing Scripts\ look further up your Path there correct one C:\Program Files\Python310\Scripts\
Delete the defect path.

Here how it look if i move geckodriver.exe to Scripts folder,still work.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.by import By
import time

#--| Setup
options = Options()
options.add_argument("--headless")
options.add_argument("window-size=1024,960")
# New
ser = Service(r"C:\Python310\Scripts\geckodriver.exe")
browser = webdriver.Firefox(service=ser, options=options)
# pip install webdriver-manager
#driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()))
#--| Parse or automation
browser.get("https://bors.e24.no/#!/instrument/PCIB.OSE/orderdepth")
time.sleep(2)
# New
volum = browser.find_element(By.CSS_SELECTOR, 'td.number.BIDVOL.number-left')
# Old
#text_type = browser.find_elements_by_css_selector('td.number.BIDVOL.number-left')
print(volum.text)
Output:
3 150

Testing Webdriver Manager for Python,i have done it virtual environment to make sure that it work.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.common.by import By
import time

#--| Setup
options = Options()
options.add_argument("--headless")
options.add_argument("window-size=1024,960")
# pip install webdriver-manager
browser = webdriver.Firefox(service=Service(GeckoDriverManager().install()))
#--| Parse or automation
browser.get("https://bors.e24.no/#!/instrument/PCIB.OSE/orderdepth")
time.sleep(2)
# New
volum = browser.find_element(By.CSS_SELECTOR, 'td.number.BIDVOL.number-left')
# Old
#text_type = browser.find_elements_by_css_selector('td.number.BIDVOL.number-left')
print(volum.text)
So you see it get driver and match it to FireFox version that you have installed.
Work the same just automate the process of getting driver an put in Path.
(webmanager_env) G:\div_code\scrape\webmanager_env
λ python bors_fireman.py


====== WebDriver manager ======
Current firefox version is 59.0
Get LATEST geckodriver version for 59.0 firefox
Driver [C:\Users\Tom\.wdm\drivers\geckodriver\win64\v0.30.0\geckodriver.exe] found in cache
3 150
Reply
#10
I'm not sure what I am looking at but when I run your first script I get the same error. When I run the 2nd script, it works:

====== WebDriver manager ======
Current firefox version is 99.0
Get LATEST geckodriver version for 99.0 firefox
There is no [win64] geckodriver for browser 99.0 in cache
Getting latest mozilla release info for v0.30.0
Trying to download new driver from https://github.com/mozilla/geckodriver/r...-win64.zip
Driver has been saved in cache [C:\Users\dap1\.wdm\drivers\geckodriver\win64\v0.30.0]
3 150

Do I have the wrong gecko driver or am I missing a library?

FWIW here is my current code:

options=Options()
options.add_argument("--headless")
ser=Service(r'C:\Program Files\Python310\Scrpits\geckodriver.exe')
browser=webdriver.Firefox(service=ser,options=options)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,661 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020