Skip to content

cannot connect to chrome at 127.0.0.1:9222 from chrome not reachable #2030

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

Closed
NourEssalam opened this issue Aug 25, 2023 · 1 comment
Closed
Labels
external Outside SeleniumBase's scope. / Ask somewhere else. question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@NourEssalam
Copy link

NourEssalam commented Aug 25, 2023

WHY AM I SEEING THIS ERROR AGAIN AND AGAIN

# from selenium import webdriver
# from selenium.webdriver.chrome.options import Options
# import undetected_chromedriver as uc
from seleniumbase import Driver
import time
 # Truing the seleniumbase, sense uc is detected
    def seleniumbase_test(self):
        driver = Driver(uc=True)
        driver.get("https://nowsecure.nl/#relax")
        time.sleep(6)
        driver.quit()

File "/home/benslimane/callcenterEPR/django/.venv/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:9222
from chrome not reachable

Stacktrace:
#0 0x55e65227ae23
#1 0x55e651fa35f6
#2 0x55e651f8e63a
#3 ...

I have already installed cft stable 116 chromedriver i have chrome 116

@mdmintz mdmintz added question Someone is looking for answers external Outside SeleniumBase's scope. / Ask somewhere else. labels Aug 25, 2023
@mdmintz
Copy link
Member

mdmintz commented Aug 25, 2023

That's a popular issue from undetected-chromedriver, with 40 open tickets so far: https://github.com/search?q=repo%3Aultrafunkamsterdam%2Fundetected-chromedriver+%22from+chrome+not+reachable%22&type=issues

To get around that, use the SB Manager format, (similar to the Driver Manager format), which has extra internal code for handling that (by using a virtual display in a headless environment). Here's a sample script: (https://github.com/seleniumbase/SeleniumBase/blob/master/examples/raw_uc_mode.py)

from seleniumbase import SB

with SB(uc=True, test=True) as sb:
    url = "https://gitlab.com/users/sign_in"
    sb.driver.uc_open_with_reconnect(url, 3)
    if not sb.is_text_visible("Username", '[for="user_login"]'):
        sb.driver.uc_open_with_reconnect(url, 4)
    sb.assert_text("Username", '[for="user_login"]', timeout=3)
    sb.assert_element('label[for="user_login"]')
    sb.highlight('button:contains("Sign in")')
    sb.highlight('h1:contains("GitLab.com")')
    sb.post_message("SeleniumBase wasn't detected", duration=4)

You could also use SeleniumBase's BaseCase format with pytest --uc.

Here's an example script using that format: (https://github.com/seleniumbase/SeleniumBase/blob/master/examples/verify_undetected.py)

from seleniumbase import BaseCase
BaseCase.main(__name__, __file__, "--uc", "-s")

class UndetectedTest(BaseCase):
    def test_browser_is_undetected(self):
        url = "https://gitlab.com/users/sign_in"
        if not self.undetectable:
            self.get_new_driver(undetectable=True)
        self.driver.uc_open_with_reconnect(url, 3)
        if not self.is_text_visible("Username", '[for="user_login"]'):
            self.get_new_driver(undetectable=True)
            self.driver.uc_open_with_reconnect(url, 4)
        self.assert_text("Username", '[for="user_login"]', timeout=3)
        self.post_message("SeleniumBase wasn't detected", duration=4)
        self._print("\n Success! Website did not detect Selenium! ")

Use self.driver to access the raw driver.
See https://github.com/seleniumbase/SeleniumBase/tree/master/examples for lots of examples.
See https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/method_summary.md for a list of methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external Outside SeleniumBase's scope. / Ask somewhere else. question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

No branches or pull requests

2 participants