Undetected selenium without chromedriver usage (Non-commercial use only!)
Project description
Selenium-Driverless (Non-commercial use only!)
- 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 - proxy-auth support (experimental, examle-code)
Questions?
Feel free to join the Diriverless-Community on Discord:)
Also, see dev-branch for the latest implementations.
dev-installation (click to expand)
pip install https://github.com/kaliiiiiiiiii/Selenium-Driverless/archive/refs/heads/dev.zip
Dependencies
- Python >= 3.7
- Google-Chrome installed (Chromium not tested)
Installing
- Install Google-Chrome
pip install selenium-driverless
Usage
with asyncio
from selenium_driverless import webdriver
from selenium_driverless.types.by import By
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.sleep(0.5)
await driver.wait_for_cdp("Page.domContentEventFired", timeout=15)
# wait 10s for elem to exist
elem = await driver.find_element(By.XPATH, '/html/body/div[2]/div/main/p[2]/a', timeout=10)
await elem.click(move_to=True)
alert = await driver.switch_to.alert
print(alert.text)
await alert.accept()
print(await driver.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.sleep(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
- use CDP events (see chrome-developer-protocoll for possible events)
Note: synchronous might not work properly
Examle Code (Click to expand)
from selenium_driverless import webdriver
import asyncio
global driver
async def on_request(params):
await driver.execute_cdp_cmd("Fetch.continueRequest", {"requestId": params['requestId']})
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
await driver.execute_cdp_cmd("Fetch.enable")
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
only works on independent webdriver.Chrome
instances.
Examle Code (Click to expand)
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
- execute
javascript
without getting detected
Examle Code (Click to expand)
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
- switch and interact with iframes
iframes = await driver.find_elements(By.TAG_NAME, "iframe")
await asyncio.sleep(0.5)
iframe_document = await iframes[0].content_document
# iframe_document.find_elements(...)
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
Examle Code (Click to expand)
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:
context_1 = driver.current_context
context_2 = await driver.new_context(proxy_bypass_list=["localhost"], proxy_server="http://localhost:5000")
await context_1.current_target.get("https://examle.com")
await context_2.get("https://examle.com")
input("press ENTER to exit:)")
asyncio.run(main())
Help
You found a bug? Feel free to open an issue:)
You've got other questions or proposials? feel free to join the Diriverless-Community on Discord or open a discusion
Note: please check the todo's below at first!
Todo's
Click to expand
- implementations
-
WebElement
s- improve
mid_location
calculation - add
WebElement.screenshot
- improve
-
Input
-
Mouse
-
mousemove
-
click
-
scroll
-
drag&drop
-
-
write
-
Touch
-
touchmove
-
TouchTap
-
scoll
-
pinch//zoom
-
-
KeyBoard
-
SendKeys
-
send files
-
-
-
- support
options.add_extension()
-
- sync
- move sync to threaded for allowing event_handlers
- support multithreading with sync version
- on independent driver instances
- on same driver instance
Authors
Copyright and Author:
Aurin Aegerter (aka Steve)
License
Unless specified differently in a single file, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Disclaimer
I am not responsible what you use the code for!!! Also no warranty!
Acknowledgments
Inspiration, code snippets, etc.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for selenium_driverless-1.6.3.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d4f7ee5343cb179f425fd738b0c5dd5ac9a5ee7639069a6ee258b4825ece901 |
|
MD5 | cd45ac64a0cfcb6d7a11ae890f37124c |
|
BLAKE2b-256 | cbee33d3f10ac451d323fe10c19af9691976406e9e665c846a84c12b3d153135 |