2

probably someone can help with Windows, Python, Selenium and using Chrome webdriver with ChromePortable.

I've defined a new folder

c:\myproject

Wihtin this folder the wedriver is located: c:\myproject\driver\chromedriver.exe

and also the Chrome Portable

c:\myproject\chromeportable\chrome.exe

Now I would like to build a simple Python script which opens - let say - stackoverflow.com.

On a computer, where google is installed it isn't a problem like

from selenium import webdriver
driver = webdriver.Chrome("c:\myproject\driver\chromedriver.exe")
driver.get("https://stackoverflow.com")

However, how to change the script if no google chrome is installed and google chrome portable should be used?

Any idea? Thank you very much in advance and have a nice day Andreas

Andreas
  • 147
  • 3
  • 17

2 Answers2

5

Use Options class:

from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "c:\myproject\chromeportable\chrome.exe"
# you may need some other options
#options.add_argument('--no-sandbox')
#options.add_argument('--no-default-browser-check')
#options.add_argument('--no-first-run')
#options.add_argument('--disable-gpu')
#options.add_argument('--disable-extensions')
#options.add_argument('--disable-default-apps')
driver = webdriver.Chrome("c:\myproject\driver\chromedriver.exe",
            options=options)
  • 1
    One more question! Google Chrome portable recorgnize not click() events. Any idea? If I use the same code with local installed chome browser (none portable version) ist works. Thank you very much in advance Best regards Andreas – Andreas Mar 15 '18 at 10:59
0
from selenium.webdriver import Chrome
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "E:\soft\GoogleChromePortableDev\App\Chrome-bin\chrome.exe"
from bs4 import BeautifulSoup
from time import sleep
from tqdm import tqdm
browser = Chrome('C:\webdriver\105_0_5195_19\chromedriver.exe')

    PS C:\parsing\sel\mvi> & C:/Python310/python.exe c:/parsing/sel/mvi/s1.py
c:\parsing\sel\mvi\s1.py:14: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  browser = Chrome('C:\webdriver\105_0_5195_19\chromedriver.exe')
Traceback (most recent call last):
  File "C:\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Python310\lib\subprocess.py", line 969, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Python310\lib\subprocess.py", line 1438, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Cannot find the specified file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\parsing\sel\mvi\s1.py", line 14, in <module>
    browser = Chrome('C:\webdriver\105_0_5195_19\chromedriver.exe')
  File "C:\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
    super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "C:\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 89, in __init__
    self.service.start()
  File "C:\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home

PS C:\parsing\sel\mvi> 

Windows 10 Python 3.10.5