We want to use Selenium in one of our apps. Locally I have everything working via the code below. The webdriver_manager
should install the Gecko render engine but the firefox GUI also seems to be used on my laptop. When I publish the app I get the execution error:
selenium.common.exceptions.SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no ‘moz:firefoxOptions.binary’ capability provided, and no binary flag set on the command line
Next, I tried installing firefox in the published app by adding packages = ["firefox"]
to my viktor toml file. However, during publishing I get the error:
ERROR packing completed with errors: Could not install all packages:
Reading package lists…
Building dependency tree…
Reading state information…
Package firefox is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package ‘firefox’ has no installation candidate
Can somebody help me with getting it to work in a published viktor app?
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager
temp_html_file = os.path.join(tempfile.gettempdir(), "map.html")
options = Options()
options.add_argument("--headless") # Run in headless mode
# options.headless = True
# Set up the Selenium WebDriver with Firefox
service = Service(GeckoDriverManager().install())
driver = webdriver.Firefox(service=service, options=options)
# Open the local HTML file
driver.get(f"file:///{temp_html_file}") # Replace with your file path
map_path = os.path.join(tempfile.gettempdir(), "map.png")
# Take a screenshot and save it
driver.get_screenshot_as_file(map_path)
# Clean up and close the browser
driver.quit()