1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Using a Python script and Selenium on WSL, how do I open and run Firefox.exe on...

Discussão em 'Python' iniciado por Stack, Setembro 30, 2024 às 23:12.

  1. Stack

    Stack Membro Participativo

    I am trying to figure out how to get my Python script running on WSL to access and run the Windows version of Firefox. I want my Python script to run on WSL, and I want the Firefox binary to be the version installed on Windows. I've been able to do simpler things like open and type into Notepad.exe with a script running on WSL, but I can't get anything to work with Firefox.exe

    I currently get a dialog box from Firefox with the error "Your Firefox profile cannot be loaded. It may be missing or inaccessible." selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1

    I've already updated to the latest version of Firefox on Windows. I've also installed geckodriver to WSL and added it to my PATH in WSL. Here's my code which I've copied from previous similar answers but doesn't work.

    import os
    from selenium import webdriver
    from selenium.webdriver.firefox.service import Service as FirefoxService
    from selenium.webdriver.firefox.options import Options

    ##### Path to the Firefox executable in Windows
    firefox_path = "/mnt/c/Program Files/Mozilla Firefox/firefox.exe"

    options = Options()
    options.binary_location = firefox_path

    service = FirefoxService()

    browser = webdriver.Firefox(service=service, options=options)

    browser.get("http://localhost:8000")

    Continue reading...

Compartilhe esta Página