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

SeleniumBase UC Mode needs a video tutorial #2000

Closed
mdmintz opened this issue Aug 14, 2023 · 4 comments
Closed

SeleniumBase UC Mode needs a video tutorial #2000

mdmintz opened this issue Aug 14, 2023 · 4 comments
Assignees
Labels
Tutorials & Learning Tutorial videos and blog posts UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@mdmintz
Copy link
Member

mdmintz commented Aug 14, 2023

SeleniumBase UC Mode needs a video tutorial

There should first be a prelude on how sites detect Selenium in general.

Then there should be an explanation on how automation frameworks can avoid being detected by websites with anti-bot services.


Key things that Selenium frameworks need to do in order to avoid getting detected:

  • Modify chromedriver to rename chromedriver-specific variables that appear in the Chrome DevTools console.
  • Launch Chrome before attaching chromedriver to it. (Don't use chromedriver to launch Chrome directly.)
  • Don't use Chrome options that are specific to Selenium (or ones that are generally only used with Selenium).
  • If using headless Chrome, make sure that you change HeadlessChrome to Chrome in the User Agent String.
  • If specifying a custom user_data_dir, make sure that the folder is never used with non-UC-Mode Chrome.
  • Disconnect chromedriver temporarily from Chrome before loading websites that try to detect chromedriver.

When all preventative measures are done correctly, Selenium should be able to enter websites appearing human:

Undetected SeleniumBase


Here are some existing examples that use --uc mode:

Here's a raw driver example:

from seleniumbase import Driver
import time

driver = Driver(uc=True)
driver.get("https://nowsecure.nl/#relax")
time.sleep(6)
driver.quit()
@mdmintz mdmintz added the Tutorials & Learning Tutorial videos and blog posts label Aug 14, 2023
@mdmintz mdmintz self-assigned this Aug 14, 2023
@mdmintz mdmintz changed the title SeleniumBase needs a video tutorial for UC Mode SeleniumBase UC Mode needs a video tutorial Aug 14, 2023
@mdmintz mdmintz added the UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode label Aug 30, 2023
@seleniumbase seleniumbase deleted a comment from aavvaavvaa Oct 1, 2023
@mdmintz
Copy link
Member Author

mdmintz commented Oct 23, 2023

Here's a multithreaded example that can be run with pytest --uc -n4

import pytest
from random import randint
from seleniumbase import BaseCase
BaseCase.main(__name__, __file__, "--uc", "-n4")


@pytest.mark.parametrize("", [[]] * 4)
def test_multi_threaded(sb):
    sb.driver.get("https://nowsecure.nl/#relax")
    sb.set_window_rect(randint(0, 750), randint(0, 400), 700, 500)
    try:
        sb.assert_text("OH YEAH, you passed!", "h1", timeout=5.25)
        sb.post_message("Selenium wasn't detected!", duration=2.8)
        sb._print("\n Success! Website did not detect Selenium! ")
    except Exception:
        sb.driver.get("https://nowsecure.nl/#relax")
        try:
            sb.assert_text("OH YEAH, you passed!", "h1", timeout=5.25)
            sb.post_message("Selenium wasn't detected!", duration=2.8)
            sb._print("\n Success! Website did not detect Selenium! ")
        except Exception:
            sb.fail('Selenium was detected! Try using: "pytest --uc"')

@mdmintz
Copy link
Member Author

mdmintz commented Oct 27, 2023

The video is ready. Enjoy! https://www.youtube.com/watch?v=5dMFI3e85ig

@mdmintz
Copy link
Member Author

mdmintz commented Nov 1, 2023

See https://www.youtube.com/@MichaelMintz/videos for my YouTube channel.

See https://www.youtube.com/playlist?list=PLp9uKicxkBc5UIlGi2BuE3aWC7JyXpD3m for the SeleniumBase playlist.

@mdmintz
Copy link
Member Author

mdmintz commented Nov 1, 2023

Closing this ticket in favor of the newer #2213

@mdmintz mdmintz closed this as completed Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tutorials & Learning Tutorial videos and blog posts UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

No branches or pull requests

1 participant