For some reason I get this error when I run my executable:
---------------------------
cx_Freeze: Python error in main script
---------------------------
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "splinter1.py", line 8, in <module>
File "C:\Python34\lib\splinter\browser.py", line 63, in Browser
return driver(*args, **kwargs)
File "C:\Python34\lib\splinter\driver\webdriver\firefox.py", line 23, in __init__
firefox_profile = FirefoxProfile(profile)
File "C:\Python34\lib\selenium\webdriver\firefox\firefox_profile.py", line 63, in __init__
WEBDRIVER_PREFERENCES)) as default_prefs:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Admin\\Desktop\\exe.win32-3.4\\library.zip\\selenium\\webdriver\\firefox\\webdriver_prefs.json'
---------------------------
OK
---------------------------
It's true, webdriver_prefs.json
was missing in the original build made by cx_freeze, but I then manually pasted it inside library.zip\\selenium\\webdriver\\firefox
, yet I still get the error.
Here is my setup file:
import sys
from cx_Freeze import setup, Executable
exe=Executable(
script="splinter1.py",
base="Win32Gui",
icon="icon.ico"
)
includefiles=[]
includes=[]
excludes=[]
packages=[]
setup(
version = "1.0",
description = "No Description",
author = "Name",
name = "Bot search",
options = {'build_exe': {'excludes':excludes,'packages':packages,'include_files':includefiles}},
executables = [exe]
)
Here is my original script:
from splinter import Browser
import contextlib
from selenium.webdriver import Remote
from selenium.webdriver.support import wait
from selenium.webdriver.support.expected_conditions import staleness_of
import time
browser = Browser('firefox')
CurrentR = 12345678
browser.visit('somewebsite')
browser.fill("field1","")
browser.fill("field2","")
browser.fill("field3",CurrentR)
#Find submit button and click
browser.find_by_id('btnSubmit').first.click()
#Wait for new page to load
class MyRemote(Remote):
@contextlib.contextmanager
def wait_for_page_load(self, timeout=30):
old_page = self.find_element_by_tag_name('html')
yield
wait(self, timeout).until(staleness_of(old_page))
print('finished')
if browser.is_text_present('No Records Selected'):
print("No records selected")
else:
print("Some records exist")
time.sleep(120)
@Thomas K
gave the correct answer. I copied the whole selenium
folder from my Lib
directory in Python and pasted it in the same directory where my .exe was.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.