2

I am currently using Chaquopy to implement Python code into Android Studio. However, I am having trouble initializing selenium's chromedriver in Python. Whenever I try initializing by using the line driver = webdriver.Chrome("/path/to/chromedriver.exe, options=opt), I either get the error "WebDriverException: Message: 'chromedriver.exe' executable may have wrong permissions" or "WebDriverException: Message: 'chromedriver' executable needs to be in PATH". So instead, I imported ChromeDriverManager and called driver = webdriver.Chrome(ChromeDriverManager().install(), options=opt). Running my program gives the following error:

    Process: com.example.test3, PID: 20964
    com.chaquo.python.PyException: ValueError: Could not get version for Chrome with this command: google-chrome --version
        at <python>.webdriver_manager.utils.chrome_version(utils.py:112)
        at <python>.webdriver_manager.driver.get_latest_release_version(driver.py:58)
        at <python>.webdriver_manager.manager.__get_latest_driver_version(manager.py:21)
        at <python>.webdriver_manager.manager.__get_version_to_download(manager.py:27)
        at <python>.webdriver_manager.manager.download_driver(manager.py:36)
        at <python>.webdriver_manager.chrome.install(chrome.py:28)
        at <python>.login.web_scrape(login.py:57)
        at <python>.chaquopy_java.call(chaquopy_java.pyx:281)
        at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrows(chaquopy_java.pyx:253)
        at com.chaquo.python.PyObject.callAttrThrows(Native Method)
        at com.chaquo.python.PyObject.callAttr(PyObject.java:209)
        at com.example.test3.LoginWaterloo$1.onClick(LoginWaterloo.java:37)
        at android.view.View.performClick(View.java:7125)
        at android.view.View.performClickInternal(View.java:7102)
        at android.view.View.access$3500(View.java:801)
        at android.view.View$PerformClick.run(View.java:27336)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Any advice on how to overcome this error? I have seen a post that shares the same problem but could not understand the answer.

iciclearms
  • 21
  • 1
  • The problem has definitly to do with what you provide in the variable 'opt'. Can you give where you give a value of opt and tell us what you wanted to do with this – dylanvanw May 19 '20 at 09:47
  • If chromedriver.exe is a Windows executable, you won't be able to run it on Android. As I understand the ChromeDriver documentation, they support using it on your Windows/Max/Linux development machine to control an Android device, but not running it on Android directly. – mhsmith May 19 '20 at 21:16
  • @dylanvanw Here is my code for initializing opt: `opt = webdriver.ChromeOptions()` and `opt.add_argument("--headless")`. I added the argument "--headless" since I expected the chromedriver to open a browser which I wanted to hide from the user. – iciclearms May 21 '20 at 18:09
  • @mhsmith Is there any way for me to run chromedriver through Android's browser(i.e. Webview)? – iciclearms May 21 '20 at 18:12
  • Sorry, I've never used any webdriver tool, so I don't know anything more. – mhsmith May 21 '20 at 20:39

1 Answers1

0

For me this worked with providing the options not to the options parameter but the chrome_options parameter.

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options,  service_args=['--verbose', '--log-path=logs/chromedriver.log'])
dylanvanw
  • 3,029
  • 1
  • 8
  • 18