Skip to main content

Selenium-Driverless

  • use selenium without chromedriver
  • currently passes cloudfare, bet365, turnstile and others
  • multiple tabs simultanously
  • multiple Incognito-contexts with individual proxy & cookies
  • async (asyncio) and sync (experimantal) support

Feel free to test my code!

See dev-branch for the latest implementations.
Installation with pip install https://github.com/kaliiiiiiiiii/Selenium-Driverless/archive/refs/heads/dev.zip

Getting Started

Dependencies

Installing

Usage

with asyncio

from selenium_driverless import webdriver
import asyncio


async def main():
    options = webdriver.ChromeOptions()
    async with webdriver.Chrome(options=options) as driver:
        await driver.get('http://nowsecure.nl#relax')
        await driver.implicitly_wait(0.5)
        await driver.wait_for_cdp("Page.domContentEventFired", timeout=15)
        
        title = await driver.title
        url = await driver.current_url
        source = await driver.page_source
        print(title)


asyncio.run(main())

synchronous

asyncified, might be buggy

from selenium_driverless.sync import webdriver

options = webdriver.ChromeOptions()
with webdriver.Chrome(options=options) as driver:
    driver.get('http://nowsecure.nl#relax')
    driver.implicitly_wait(0.5)
    driver.wait_for_cdp("Page.domContentEventFired", timeout=15)

    title = driver.title
    url = driver.current_url
    source = driver.page_source
    print(title)

custom debugger address

from selenium_driverless import webdriver

options = webdriver.ChromeOptions()
options.debugger_address = "127.0.0.1:2005"

# specify if you don't want to run remote
# options.add_argument("--remote-debugging-port=2005")

async with webdriver.Chrome(options=options) as driver:
  await driver.get('http://nowsecure.nl#relax', wait_load=True)

use events

Note: synchronous might not work properly

from selenium_driverless import webdriver
import asyncio

global driver


async def on_request(params):
    await driver.execute_cdp_cmd("Fetch.continueRequest", {"requestId": params['requestId']},
                                 disconnect_connect=False)
    print(params["request"]["url"])


async def main():
    global driver
    options = webdriver.ChromeOptions()
    async with webdriver.Chrome(options=options) as driver:
        await driver.get('http://nowsecure.nl#relax')

        # enable Fetch, we don't want to disconnect after "Fetch.enable"
        await driver.execute_cdp_cmd("Fetch.enable", disconnect_connect=False)
        await driver.add_cdp_listener("Fetch.requestPaused", on_request)

        await driver.wait_for_cdp(event="Page.loadEventFired", timeout=5)

        await driver.remove_cdp_listener("Fetch.requestPaused", on_request)
        await driver.execute_cdp_cmd("Fetch.disable")

        print(await driver.title)


asyncio.run(main())

Multiple tabs simultously

Note: asyncio is recommendet, threading has been reported not too work

from selenium_driverless.sync import webdriver
from selenium_driverless.utils.utils import read
from selenium_driverless import webdriver
import asyncio


async def target_1_handler(target):
    await target.get('https://abrahamjuliot.github.io/creepjs/')
    print(await target.title)


async def target_2_handler(target):
    await target.get("about:blank")
    await target.execute_script(script=read("/files/js/show_mousemove.js"))
    await target.pointer.move_to(500, 500, total_time=2)


async def main():
    options = webdriver.ChromeOptions()
    async with webdriver.Chrome(options=options) as driver:
        target_1 = await driver.current_target
        target_2 = await driver.switch_to.new_window("tab", activate=False)
        await asyncio.gather(
            target_1_handler(target_1),
            target_2_handler(target_2)
        )
        await target_1.focus()
        input("press ENTER to exit")


asyncio.run(main())

Unique execution contexts

from selenium_driverless.sync import webdriver
from selenium_driverless import webdriver
import asyncio


async def main():
    options = webdriver.ChromeOptions()
    async with webdriver.Chrome(options=options) as driver:
        await driver.get('chrome://version')
        script = """
        const proxy = new Proxy(document.documentElement, {
          get(target, prop, receiver) {
            if(prop === "outerHTML"){
                console.log('detected access on "'+prop+'"', receiver)
                return "mocked value:)"
            }
            else{return Reflect.get(...arguments)}
          },
        });
        Object.defineProperty(document, "documentElement", {
          value: proxy
        })
        """
        await driver.execute_script(script)
        src = await driver.execute_script("return document.documentElement.outerHTML", unique_context=True)
        mocked = await driver.execute_script("return document.documentElement.outerHTML", unique_context=False)
        print(src, mocked)


asyncio.run(main())

Pointer Interaction

see @master/dev/show_mousemove.py for visualization

pointer = await driver.current_pointer
move_kwargs = {"total_time": 0.7, "accel": 2, "smooth_soft": 20}

await pointer.move_to(100, 500)
await pointer.click(500, 50, move_kwargs=move_kwargs, move_to=True)

Iframes

iframes = await driver.find_elements(By.TAG_NAME, "iframe")
await asyncio.sleep(0.5)
target = await driver.get_target_for_iframe(iframes[0])

multiple contexts

  • different cookies for each context
  • A context can have multiple windows and tabs within
  • different proxy for each context
  • opens as a window as incognito

Help

Please feel free to open an issue or fork! note: please check the todo's below at first!

Todo

Deprecated

Authors

Aurin Aegerter

License

Shield: CC BY-NC-SA 4.0

Unless specified differently in a single file, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

CC BY-NC-SA 4.0

Disclaimer

I am not responsible what you use the code for!!! Also no warranty!

Acknowledgments

Inspiration, code snippets, etc.

Metadata

Release files for selenium-driverless 1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for selenium-driverless 1.5
File Size Uploaded
selenium_driverless-1.5.tar.gz 61.4 kB Details

Release files / selenium_driverless-1.5.tar.gz

Download URL selenium_driverless-1.5.tar.gz
Size 61.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a8b97fe05c441073cface9dc81ad666ee2ed7306d487f5816e91a083fb3824a2
BLAKE2b-256 checksum
How to use checksums
38a183517eb19d2238d8cc416ed3c3406ec2b7347058324fa49b37304ade0537
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.9

Release history Release notifications | RSS feed

1.9.4

1 release file

1.9.3.1

1 release file

1.9.3

1 release file

1.9.2

1 release file

1.9.1

1 release file

1.9

1 release file

1.8.0.2

1 release file

1.8

1 release file

1.7.3

1 release file

1.7.2

1 release file

1.7.1

1 release file

1.7

1 release file

1.6.3.3

1 release file

1.6.3.1

1 release file

1.6.3

1 release file

1.6.2

1 release file

1.6.1

1 release file

1.6

1 release file

1.5.2

1 release file

1.5.1

1 release file

This release

1.5 This release

1 release file

1.4.2

1 release file

1.4.1

1 release file

1.4

1 release file

1.3.4

1 release file

1.3.3

1 release file

1.3.2.1

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3

1 release file

1.2.7

1 release file

1.2.6

1 release file

1.2.5

1 release file

1.2.4

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page