1

I have been trying to automate my firefox browser in Kali linux. I installed selenium and geckdriver and running this simple script:

from selenium import webdriver
browser = webdriver.Firefox('/usr/bin/')
browser.get('www.duckduckgo.com')

#I saw a video where the guy mentioned that we do not have to use the path of the browser (doesn't work for me)

After running this simple script in python as python3 script.py the terminal freezes at:

script.py:4: DeprecationWarning: firefox_profile has been deprecated, please pass in a Service object

After Interrupting the process, it delivers the following error:

  browser = webdriver.Firefox('/usr/bin/')
^CTraceback (most recent call last):
  File "script.py", line 4, in <module>
    browser = webdriver.Firefox('/usr/bin/')
  File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/webdriver.py", line 155, in __init__
    firefox_profile = FirefoxProfile(firefox_profile)
  File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/firefox_profile.py", line 78, in __init__
    ignore=shutil.ignore_patterns("parent.lock", "lock", ".parentlock"))
  File "/usr/lib/python3.7/shutil.py", line 354, in copytree
    copy_function(srcname, dstname)
  File "/usr/lib/python3.7/shutil.py", line 266, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/lib/python3.7/shutil.py", line 122, in copyfile
    copyfileobj(fsrc, fdst)
  File "/usr/lib/python3.7/shutil.py", line 79, in copyfileobj
    buf = fsrc.read(length)
KeyboardInterrupt

I really do not understand what does it mean. Can you please help me fix it? Thanks in advance.

PS: I also installed geckodriver v0.26 and put in the same directory as the script.py file.

probably-asskicker
  • 171
  • 1
  • 3
  • 14
  • Can you elaborate on what the expected behavior is? The deprecation warning should be just that: a warning. Likewise, the trackeback is simply a result of you interrupting the process (hence the exception name `KeyboardInterrupt`). Neither of these are unusual in and of themselves. – Brian61354270 Apr 12 '20 at 15:35
  • It doesnt show any process or progress but when I interrupt it, it displays those other details I mentioned in the problem. – probably-asskicker Apr 12 '20 at 17:28
  • What "process or progress" do you expect to see? You don't include `print` calls or other forms of IO in your script. Also, the `kali-linux` tag doesn't seem to be relevant here since your question doesn't relate to distribution-specific behavior. – Brian61354270 Apr 12 '20 at 17:37

2 Answers2

0

Use this command for find the correct location of your geckdriver

$ Which geckdriver

and try this

path = '<your driver location>'
browser = webdriver.Firefox(executable_path=path)
shihar
  • 48
  • 7
0
def setFirefoxDriver():
    from selenium import webdriver
    from selenium.webdriver.firefox.service import Service

    driverPath = r'yourPathHere\geckodriver.exe'
    dService = Service(driverPath)
    d = webdriver.Firefox(service=dService)

    return d

d.get('site.com')
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 07 '22 at 22:45
  • 2
    The question asks about using a Service Object, I explicitly put the code with the Service object. The only way to explain it more clear is by adding reduntant infromation. – user18672350 Oct 08 '22 at 11:43