0

I can run chromedriver.exe from the same folder where the program is located:

def webdrivers():
    dir = os.path.dirname(os.path.abspath(__file__))
    webdrivers = dir + "\\chromedriver.exe"
    return(webdrivers)
driver = webdriver.Chrome(webdrivers(), options=option)

And it works...

But how to do this to enable the Brave browser from an application shortcut that is in the same folder as the program? I tried:

def bravebrowser():
    dir = os.path.dirname(os.path.abspath(__file__))
    bravebrowser = dir + "\\Brave.lnk"
    return(bravebrowser)

When I run the program and display bravebrowser(), the path is right in print() and that's exactly where the shortcut to the Brave browser is, but when I use it, it doesn't work (brave not start).

print:

C:\Users\Admin\Desktop\Program\Brave.lnk

but that not work...:

option.binary_location(bravebrowser())

Some solution?

Owneds
  • 13
  • 5
  • `.lnk` can be treated as text file - better use path to real `.exe` file. – furas Jun 11 '21 at 06:16
  • Yes i know, but i want use compiled program on other computer where the location of the file (brave) may be different, so I wanted it to be run with a shortcut that was placed in the program folder the same as chromedriver – Owneds Jun 11 '21 at 06:27
  • better write path in some file like JSON and read it from this file. OR find module which can get path to `.exe` from file `.lnk` – furas Jun 11 '21 at 06:34
  • [Reading the target of a .lnk file in Python?](https://stackoverflow.com/questions/397125/reading-the-target-of-a-lnk-file-in-python) – furas Jun 11 '21 at 06:35
  • Thank you, your link helped me a lot. Indeed, referencing the exe based on the hash was a perfect idea. I didn't think about it before! Can You Know maybe how to make from that link realpath in output? Like: `C:\Program Files\BraveSoftware\brave.exe `convert to correct like: `r'C:\Program Files\BraveSoftware\brave.exe' `? because my script need realpath output – Owneds Jun 11 '21 at 07:04
  • do you mean prefix `r`? This prefix is used only to put path directly in code - if you get path from file then you should have correct path. And if you get error then show full error message in new question on new page. – furas Jun 11 '21 at 11:58

0 Answers0