Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to specify the Chromium browser binary used #1709

Closed
mdmintz opened this issue Jan 27, 2023 · 7 comments · Fixed by #1714
Closed

Add an option to specify the Chromium browser binary used #1709

mdmintz opened this issue Jan 27, 2023 · 7 comments · Fixed by #1714
Assignees
Labels
enhancement Making things better SeleniumBase 4 SeleniumBase 4

Comments

@mdmintz
Copy link
Member

mdmintz commented Jan 27, 2023

Add an option to specify the Chromium browser binary used

(For the browser executable, NOT the driver)

Supports the two main Chromium browsers: Chrome and Edge.

Example:

pytest test_demo_site.py --binary-location="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"

Also as an option for other Syntax Formats:

from seleniumbase import Driver
from seleniumbase import js_utils
from seleniumbase import page_actions

driver = Driver(browser="chrome", binary_location="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
try:
    driver.get("https://seleniumbase.io/apps/calculator")
    page_actions.wait_for_element(driver, "4", by="id").click()
    page_actions.wait_for_element(driver, "2", by="id").click()
    page_actions.wait_for_text(driver, "42", "output", by="id")
    js_utils.highlight_with_js(driver, "#output", loops=6)
finally:
    driver.quit()
@mdmintz mdmintz added enhancement Making things better SeleniumBase 4 SeleniumBase 4 labels Jan 27, 2023
@mdmintz mdmintz self-assigned this Jan 27, 2023
@mdmintz
Copy link
Member Author

mdmintz commented Jan 29, 2023

@mingatupturndotorg
Copy link

mingatupturndotorg commented Dec 19, 2023

hello @mdmintz! first, thank you for the hard work on seleniumbase, it is much appreciated.

I've searched through closed issues on setting binary location and WSL, but haven't found anything too similar. I recognize this could fully be user error, but here goes.

I'm using:
-WSL: Ubuntu-22.04
-chromedriver 120.0.6099.109 (installed via 'sbase get chromedriver 120', it was defaulting to installing version 114)
-sbase4.22.0

Running the following:
CHROME_PATH = "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" driver = Driver( uc=True, binary_location=CHROME_PATH )

results in the following error:

Warning: The Chromium binary specified is NOT valid!
Expecting "chrome.exe" to be found in ['google-chrome', 'google-chrome-stable', 'chrome', 'chromium', 'chromium-browser', 'google-chrome-beta', 'google-chrome-dev', 'google-chrome-unstable', 'brave-browser', 'brave-browser-stable', 'opera', 'opera-stable'] for the browser / OS!
(Will use default settings...)

It appears that sbase rightfully recognizes that I'm running code in Linux, and thus does not consider the binary location in Windows valid since it does not match the constants, but shouldn't setting binary_location overcome that expectation?

Both

'/mnt/c/Program Files/Google/Chrome Beta/Application/chrome.exe',
'/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'

are also set to PATH, and appear when running os.environ.get("PATH").split(os.pathsep).

From searching through other issues, this function doesn't return anything:
print(detect_b_ver.chrome_on_windows_path())

Any insight or troubleshooting is appreciated, thanks again!

@mdmintz
Copy link
Member Author

mdmintz commented Dec 19, 2023

Hello @mingatupturndotorg, you mentioned that you're running on Ubuntu-22.04, yet you're trying to use a .exe file.

.exe files aren't supported on Ubuntu. You should use one from the list provided: ['google-chrome', 'google-chrome-stable', 'chrome', 'chromium', 'chromium-browser', 'google-chrome-beta', 'google-chrome-dev', 'google-chrome-unstable', 'brave-browser', 'brave-browser-stable', 'opera', 'opera-stable'] (Those files don't have a file extension.)

For a Linux system, those are the supported binaries to choose from. Using a different one would lead to errors, so that is prevented during binary selection.

@mingatupturndotorg
Copy link

Thanks @mdmintz, that's a fair response. To clarify my use case or expected behavior - when using undetected-chromedriver, I could run the following script in Ubuntu with WSL:

CHROME_PATH = '/mnt/c/Program Files/Google/Chrome Beta/Application/chrome.exe'

options = uc.ChromeOptions()
options.binary_location = CHROME_PATH
driver = uc.Chrome(options=options)

and a headful Chrome installed in Windows would appear. Is that behavior possible with sbase?

@mdmintz
Copy link
Member Author

mdmintz commented Dec 19, 2023

@mingatupturndotorg I had not considered WSL (Windows Subsystem for Linux) - (https://ubuntu.com/wsl).
I'll add chrome.exe as a valid option for binary_location on Linux. That may resolve your issue.
(Will be in the next release.)

@mingatupturndotorg
Copy link

Thanks! Would a temporary fix be to add chrome.exe to valid_chrome_binaries_on_linux in constants.py?

@mdmintz
Copy link
Member Author

mdmintz commented Dec 19, 2023

@mingatupturndotorg Yes, try that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Making things better SeleniumBase 4 SeleniumBase 4
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants