mherrmann/helium

Change Chromedriver Path

Closed this issue · 18 comments

Hi,
So i have a Script that uses Chromedriver and i want it to run on Heroku, but the problem is that you need to change the Chromedriver path to something like that: options.binary_location = os.environ.get("GOOGLE_CHROME_BIN") and the Start needs to look like that: (executable_path=os.environ.get("CHROMEDRIVER_PATH"),options=options) (Thats code from Selenium).
Is there a way to do something like that?
Thanks.

I've been thinking about making Helium try to find Chromedriver from PATH first before using its own copy. Would that help?

@mherrmann So the Problem is, there is nothing like a PATH in Heroku (As much as i know), you need to configure some things so the only possible solution would be to do something like that, maybe you could just add an option like that: options.chrome_driver_path = 'The_Path'

I'm not familiar with Heroku but can't you initiate the selenium driver with a path?

from selenium import webdriver

driver = webdriver.Chrome('/path/to/chromedriver')

and then just use helium's set_driver(driver)?

Nope, then you just get an error @dntzbgh

@mherrmann any news here?

I won't have time to do it. If you want it, please submit a PR. As I said, ideally helium would pick up the chrome and ff drivers from Path.

Is there any known workaround for this issue?

@mherrmann Hey, I'd like to work on this. Could you offer some guidance as to what you'd like to be implemented. Finding the driver in PATH is a great solution and should certainly be the default - I agree. But do you plan to ship a driver with this library regularly? It might get unmaintainable in my opinion. Perhaps letting the user simply pass in an executable path (optional - if they want to explicitly specify a webdriver) is a better choice?

Hi! Yes, I can offer some guidance!

I think the default should be for Helium to try and start from PATH. If that fails, it should revert to its own copy. So the code should be along the lines of:

try:
    # start from PATH
except SomeAppropriateException:
    # start from own copy

This for both start_chrome and start_firefox.

Regarding your second point: You're right that the web driver shipped with helium will quickly become outdated. To fix this, I think the following would be best: A separate package on PyPI, helium_chromedriver that contains the Chrome driver in that version. So eg. helium_chromedriver==86.0.4240.22 would contain that version of the driver. The helium package itself would then have a dependency on helium_chromedriver.

To shield Helium from incompatibilites between Chromedriver versions, the helium_chromedriver package should not just contain the binary but a unified Python function, say helium_chromedriver.start_chrome(...) that contains the necessary logic.

@mherrmann Could you elaborate on the incompatibility between the driver bit? What exactly needs to be checked to ensure the drivers are indeed compatible? If I'm not mistaken, the compatibility depends on whether or not, for example, the chromedriver binary supports the actual chrome browser installed in the user's machine. Is there any other compatibility that needs to be checked?

Also how do you plan to implement the separate package? I'm willing to work on it as well but would it be on the same repo, or a different repo for organization's sake?

Sure. For example: A very old version of ChromeDriver was printing ugly warnings on stdout when you started it. Helium had some special code to suppress these warnings for that specific ChromeDriver version. Verison 1.2.3 of the helium_chromedriver package would include such logic if necessary for ChromeDriver 1.2.3 etc.

helium_chromedriver would be in a different repo.

@mherrmann I implemented the default pickup from PATH functionality. Should I open a PR to a different branch so you can review? If so, could you suggest which branch to PR to

PR to master is fine, thanks.

I just released Helium 3.0.5 that uses the chrome- and geckodriver from your PATH and only falls back to Helium's own binaries if they can't be found there. Thank you again @TotallyNotChase for the PR.

@mherrmann Does it now support specifying the path to chromedriver.exe? For example, instead of putting it in PATH, I put chromedriver.exe in the directory of the py file.

Or is it possible to add a parameter to manually specify executable_path

driver = start_chrome(executable_path=r".\chromedriver.exe")

@XHXIAIEIN it doesn't currently support specifying the path to chromedriver.exe *. In the scenario you described, why don't you put the directory of the py file on the PATH?

*: It does support specifying the path to chromedriver.exe if you start Chrome with Selenium instead of start_chrome(...).

@XHXIAIEIN it doesn't currently support specifying the path to chromedriver.exe *. In the scenario you described, why don't you put the directory of the py file on the PATH?

I'm writing a script for downloading email attachments for computer beginners. It is a very painful thing to explain "Path", even if you write detailed operation steps.

If there is support for specifying the path to chromedriver.exe, I can just put it together with the .py file, which would be much easier.

D:
└───folder
    ├───file.py
    ├───chromedriver.exe

*: It does support specifying the path to chromedriver.exe if you start Chrome with Selenium instead of start_chrome(...).

I know it's possible to use Selenium's methods inside helium.

get_driver().find_elements_by_class_name('name')

I don't know before that Selenium can be used with helium together. Now I know how to use it :)

from selenium import webdriver
from helium import *

# selenium
driver_path  = "./chromedriver.exe" 
driver = webdriver.Chrome(driver_path)
driver.get("https://www.google.com")

# helium
set_driver(driver)
go_to("github.com/login")
write("user", into="Username")

But I don’t know why, it feels like the process of go_to is very slow

I'm writing a script for downloading email attachments for computer beginners. It is a very painful thing to explain "Path", even if you write detailed operation steps.

I think you can just edit os.environ from your script.

import os
os.environ['PATH'] += ';' + os.getcwd()