Compile error using Selenium: Binary is not a Firefox Executable

Asked

Viewed 50 times

1

I made the following script:

#/usr/bin/env python3 -u

import time
import sys
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

# Habilita ou não o salvar
MODO_TESTE=True
# MODO_TESTE=False


URL='https://4496263.app.netsuite.com/app/accounting/transactions/timebill.nl?whence='


USERNAME='[email protected]'
try:
    with open('.senha', 'r') as p:
        PASSWORD=p.read()
except IOError:
        print('Não existe o arquivo .senha no diretorio atual')
        sys.exit(1)


XPATH_USERNAME='//*[@id="userName"]'
XPATH_PASSWORD='//*[@id="password"]'
XPATH_BTNLOGIN='//*[@id="login-submit"]'


XPATH_DATA='//*[@id="trandate"]'
XPATH_HORAS='//*[@id="hours"]'
XPATH_CLIENTE='//*[@id="customer_display"]'
XPATH_CHAMADO='//*[@id="casetaskevent_display"]'
XPATH_ATIVIDADE='//*[@id="inpt_item1"]'
XPATH_DESCRICAO='//*[@id="memo"]'

XPATH_BTNSALVAR='//*[@id="secondarysavesubmit"]'

binary = FirefoxBinary('C:\\Users\\EMPRESA\\Desktop\\LANCAMENTODEHORAS\\geckodriver.exe')
browser = webdriver.Firefox(firefox_binary=binary)


def limpaCampos():
    browser.find_element_by_xpath(XPATH_DATA).send_keys(Keys.CONTROL, 'a')
    browser.find_element_by_xpath(XPATH_DATA).send_keys('')

    browser.find_element_by_xpath(XPATH_HORAS).send_keys(Keys.CONTROL, 'a')
    browser.find_element_by_xpath(XPATH_HORAS).send_keys('')

    browser.find_element_by_xpath(XPATH_CLIENTE).send_keys(Keys.CONTROL,'a')
    browser.find_element_by_xpath(XPATH_CLIENTE).send_keys('')


def preencheInformacoes(data,hora,cliente,chamado,atividade,descricao):


    # Reset de todos os campos só pra confimar e testar se está tudo ok
    limpaCampos()

    browser.find_element_by_xpath(XPATH_DATA).send_keys(Keys.CONTROL, 'a')
    browser.find_element_by_xpath(XPATH_DATA).send_keys(str(data))
    time.sleep(1)


    browser.find_element_by_xpath(XPATH_HORAS).send_keys(str(hora))

    browser.find_element_by_xpath(XPATH_CLIENTE).send_keys(Keys.CONTROL,'a')
    time.sleep(1)
    browser.find_element_by_xpath(XPATH_CLIENTE).send_keys(str(cliente))
    browser.find_element_by_xpath(XPATH_CLIENTE).send_keys(Keys.TAB)

    # Verifica se tem chamado
    if (int(chamado) != 0 ):
       browser.find_element_by_xpath(XPATH_CHAMADO).send_keys('Chamado # ' + str(chamado))
       browser.find_element_by_xpath(XPATH_CLIENTE).send_keys(Keys.TAB)


    browser.find_element_by_xpath(XPATH_ATIVIDADE).send_keys(str(atividade))

    browser.find_element_by_xpath(XPATH_DESCRICAO).send_keys(str(descricao.replace('\\n','')))

    time.sleep(1)

    if MODO_TESTE:
        print ('Nao está salvando')
    else:
        browser.find_element_by_xpath(XPATH_BTNSALVAR).click();

def parsingArquivo(fileName):
    fileHandle = open(fileName, 'r')

    linha = 1
    for line in fileHandle:
        fields = line.split('|')

        print ( str(linha) + "-> " + str(fields) )

        data=fields[2]
        cliente=fields[3].split(':')[0]
        atividade=fields[4]
        chamado=int(fields[5])
        hora=fields[6]
        descricao=fields[7]

        preencheInformacoes(data,hora,cliente,chamado,atividade,descricao)
        linha +=1

    fileHandle.close()

def main():
    print('Inicio ...')
    print(datetime.now())
    if MODO_TESTE:
        print ('Estamos em MODO de TESTE')

    browser.get(URL)

    browser.find_element_by_xpath(XPATH_USERNAME).send_keys(str(USERNAME))
    browser.find_element_by_xpath(XPATH_PASSWORD).send_keys(str(PASSWORD))
    browser.find_element_by_xpath(XPATH_BTNLOGIN).click()

    parsingArquivo('./lancar')

    # browser.quit()
    print('Fim ...')
    print(datetime.now())

if __name__ == '__main__':
        main()

And it returns this error:

C:\Users\EMPRESA\Desktop\LANCAMENTODEHORAS>python Apontar.py
Traceback (most recent call last):
  File "C:\Users\EMPRESA\Desktop\LANCAMENTODEHORAS\Apontar.py", line 42, in <module>
    browser = webdriver.Firefox(firefox_binary=binary)
  File "C:\Users\EMPRESA\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
    RemoteWebDriver.__init__(
  File "C:\Users\EMPRESA\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\EMPRESA\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\EMPRESA\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\EMPRESA\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable

Important detail it runs on LINUX normally.

1 answer

2


Firefoxbinary has to point to Firefox binary (executable), not geckodriver binary.

The configuration below should work:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

options = Options()
options.binary = FirefoxBinary(r'/caminho/para/o/binario/do/firefox')
options.headless = True  # !!!!!!

browser = webdriver.Firefox(executable_path=r'/caminho/para/o/geckodriver', options=options)

Note Commenting on the line with options.headless or setting for False, should open the browser. What is best to do before testing headless.

  • Perfect, Paul. It worked correctly. Thank you very much!

  • Oops! Good to know that it worked. If you think pertinent, mark the answer as accepted. Enjoy and look at this post

  • Marked!!! Vlaeueu!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.