Skip to content

Commit

Permalink
add workflow. removed forgotten print statement, adjusted docs a bit.…
Browse files Browse the repository at this point in the history
… remember, this repo is still building up, usage may cause problems
  • Loading branch information
UltrafunkAmsterdam committed Feb 20, 2024
1 parent 064d6ef commit 0285a7c
Show file tree
Hide file tree
Showing 7 changed files with 5,094 additions and 283 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: 'docs/_build/html'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
5,083 changes: 4,837 additions & 246 deletions docs/_build/markdown/index.md

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions docs/_build/markdown/nodriver/cdp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# CDP object

* [Accessibility](cdp/accessibility.md)
* [Animation](cdp/animation.md)
* [Audits](cdp/audits.md)
* [Autofill](cdp/autofill.md)
* [BackgroundService](cdp/background_service.md)
* [Browser](cdp/browser.md)
* [CacheStorage](cdp/cache_storage.md)
* [Cast](cdp/cast.md)
* [Console](cdp/console.md)
* [CSS](cdp/css.md)
* [Database](cdp/database.md)
* [Debugger](cdp/debugger.md)
* [DeviceAccess](cdp/device_access.md)
* [DeviceOrientation](cdp/device_orientation.md)
* [DOM](cdp/dom.md)
* [DOMDebugger](cdp/dom_debugger.md)
* [DOMSnapshot](cdp/dom_snapshot.md)
* [DOMStorage](cdp/dom_storage.md)
* [Emulation](cdp/emulation.md)
* [EventBreakpoints](cdp/event_breakpoints.md)
* [FedCm](cdp/fed_cm.md)
* [Fetch](cdp/fetch.md)
* [HeadlessExperimental](cdp/headless_experimental.md)
* [HeapProfiler](cdp/heap_profiler.md)
* [IndexedDB](cdp/indexed_db.md)
* [Input](cdp/input_.md)
* [Inspector](cdp/inspector.md)
* [IO](cdp/io.md)
* [LayerTree](cdp/layer_tree.md)
* [Log](cdp/log.md)
* [Media](cdp/media.md)
* [Memory](cdp/memory.md)
* [Network](cdp/network.md)
* [Overlay](cdp/overlay.md)
* [Page](cdp/page.md)
* [Performance](cdp/performance.md)
* [PerformanceTimeline](cdp/performance_timeline.md)
* [Preload](cdp/preload.md)
* [Profiler](cdp/profiler.md)
* [Runtime](cdp/runtime.md)
* [Schema](cdp/schema.md)
* [Security](cdp/security.md)
* [ServiceWorker](cdp/service_worker.md)
* [Storage](cdp/storage.md)
* [SystemInfo](cdp/system_info.md)
* [Target](cdp/target.md)
* [Tethering](cdp/tethering.md)
* [Tracing](cdp/tracing.md)
* [WebAudio](cdp/web_audio.md)
* [WebAuthn](cdp/web_authn.md)
16 changes: 16 additions & 0 deletions docs/_build/markdown/nodriver/classes/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ entry point for creating an instance
* **Return type:**
[`Browser`](#nodriver.Browser)

#### config *: [`Config`](others_and_helpers.md#nodriver.Config)*

#### targets *: [`List`](https://docs.python.org/3/library/typing.html#typing.List)*

current targets (all types

#### connection *: `Connection`*

#### *property* websocket_url

#### *property* main_tab *: [Tab](tab.md#nodriver.Tab)*

returns the target which was launched with the browser
Expand All @@ -49,6 +55,10 @@ returns the target which was launched with the browser
returns the current targets which are of type “page”
:return:

#### *property* cookies *: CookieJar*

#### *property* stopped

#### *async* wait(time=1)

wait for <time> seconds. important to use, especially in between page navigation
Expand Down Expand Up @@ -119,3 +129,9 @@ grant permissions for:
wakeLockScreen
wakeLockSystem
windowManagement

#### *async* tile_windows(max_columns=0)

#### *async* update_targets()

#### stop()
101 changes: 99 additions & 2 deletions docs/_build/markdown/nodriver/classes/element.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,80 @@ Some words about the Element class

### *class* Element(node, tab, tree=None)

#### *property* tag

#### *property* tag_name

#### *property* node_id

#### *property* backend_node_id

#### *property* node_type

#### *property* node_name

#### *property* local_name

#### *property* node_value

#### *property* parent_id

#### *property* child_node_count

#### *property* attributes

#### *property* document_url

#### *property* base_url

#### *property* public_id

#### *property* system_id

#### *property* internal_subset

#### *property* xml_version

#### *property* value

#### *property* pseudo_type

#### *property* pseudo_identifier

#### *property* shadow_root_type

#### *property* frame_id

#### *property* content_document

#### *property* shadow_roots

#### *property* template_content

#### *property* pseudo_elements

#### *property* imported_document

#### *property* distributed_nodes

#### *property* is_svg

#### *property* compatibility_mode

#### *property* assigned_slot

#### *property* tab

#### *async* save_to_dom()

#### *async* remove_from_dom()

#### *async* update(\_node=None)

updates element to retrieve more properties. for example this enables
[`children`](#nodriver.Element.children) and `parent` attributes.
[`children`](#nodriver.Element.children) and [`parent`](#nodriver.Element.parent) attributes.

also resolves js opbject which is stored object in `remote_object`
also resolves js opbject which is stored object in [`remote_object`](#nodriver.Element.remote_object)

usually you will get element nodes by the usage of

Expand All @@ -29,6 +97,12 @@ therefore, it is not advised to call this method on a bunch of blocks (100+) at
* **Returns:**
* **Return type:**

#### *property* node

#### *property* tree *: [Node](../cdp/dom.md#nodriver.cdp.dom.Node)*

#### *property* parent *: [Element](#nodriver.Element) | [None](https://docs.python.org/3/library/constants.html#None)*

#### *property* attrs

attributes are stored here, however, you can set them directly on the element object as well.
Expand All @@ -42,13 +116,19 @@ so you can browse through the entire tree as well.
:return:
:rtype:

#### *property* remote_object *: [RemoteObject](../cdp/runtime.md#nodriver.cdp.runtime.RemoteObject)*

#### *property* object_id *: [RemoteObjectId](../cdp/runtime.md#nodriver.cdp.runtime.RemoteObjectId)*

#### *async* click()

Click the element.

* **Returns:**
* **Return type:**

#### *async* get_js_attributes()

#### *async* apply(js_function, return_by_value=True)

apply javascript to this element. the given js_function string should accept the js element as parameter,
Expand All @@ -64,6 +144,11 @@ eg:
* **Returns:**
* **Return type:**

#### *async* get_position(abs=False)

* **Return type:**
`Position`

#### *async* mouse_click(button='left', buttons=1, modifiers=0, \_until_event=None)

native click (on element) . note: this likely does not work atm, use click() instead
Expand Down Expand Up @@ -123,6 +208,12 @@ for form (select) fields. when you have queried the options you can call this me
calling `option.select_option()` will use that option as selected value.
does not work in all cases.

#### *async* set_value(value)

#### *async* set_text(value)

#### *async* get_html()

#### *property* text *: [str](https://docs.python.org/3/library/stdtypes.html#str)*

gets the text contents of this element
Expand All @@ -138,6 +229,10 @@ note: this includes text in the form of script content, as those are also just
:return:
:rtype:

#### *async* query_selector_all(selector)

#### *async* query_selector(selector)

#### *async* save_screenshot(filename='auto', format='jpeg', scale=1)

Saves a screenshot of this element (only)
Expand Down Expand Up @@ -182,3 +277,5 @@ when any of the follow happens:
- video stops

the video recorded will be downloaded.

#### *async* is_recording()
50 changes: 38 additions & 12 deletions docs/_build/markdown/nodriver/classes/tab.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<a id="tab"></a>

# Tab class

### *class* Tab(websocket_url, target, browser=None, \*\*kwargs)

tab is the controlling mechanism/connection to a ‘target’,
[Tab class](#tab) is the controlling mechanism/connection to a ‘target’,
for most of us ‘target’ can be read as ‘tab’. however it could also
be an iframe, serviceworker or background script for example,
although there isn’t much to control for those.
Expand All @@ -14,6 +16,8 @@ When you browse to another page, the tab will be the same (it is an browser view
So it’s important to keep some reference to tab objects, in case you’re
done interacting with elements and want to operate on the page level again.

## Custom CDP commands

Tab object provide many useful and often-used methods. It is also
possible to utilize the included cdp classes to to something totally custom.

Expand All @@ -32,32 +36,54 @@ this way you can build very detailed and customized commands.
(note: finding correct command combo’s can be a time consuming task, luckily i added a whole bunch
of useful methods, preferably having the same api’s or lookalikes, as in selenium)

# some useful, often needed and simply required methods
### some useful, often needed and simply required methods

## [`find()`](#nodriver.Tab.find) | find(text)

find and returns a single element by text match. by default returns the first element found.
much more powerful is the best_match flag, although also much more expensive.
when no match is found, it will retry for <timeout> seconds (default: 10), so
this is also suitable to use as wait condition.

## [`query_selector_all()`](#nodriver.Tab.query_selector_all)
## [`find()`](#nodriver.Tab.find) | find(text, best_match=True) or find(text, True)

this is just like javascripts’ document.querySelectorAll, which you can use
to quickly select elements based a css selector.
Much more powerful (and expensive!!) than the above, is the use of the `find(text, best_match=True)` flag.
It will still return 1 element, but when multiple matches are found, picks the one having the
most similar text length.
How would that help?
For example, you search for “login”, you’d probably want the “login” button element,
and not thousands of scripts,meta,headings which happens to contain a string of “login”.

tip: you can also use `await page('.your-css-selector')`
when no match is found, it will retry for <timeout> seconds (default: 10), so
this is also suitable to use as wait condition.

## [`find_element_by_text()`](#nodriver.Tab.find_element_by_text)
## [`select()`](#nodriver.Tab.select) | select(selector)

this is almost like query_selector all, but performs a text search and returns
any elements that matches. This is case insensitive.
find and returns a single element by css selector match.
when no match is found, it will retry for <timeout> seconds (default: 10), so
this is also suitable to use as wait condition.

tip: you can also use `await page(text='sign up')`
## [`select_all()`](#nodriver.Tab.select_all) | select_all(selector)

## await `Page`
find and returns all elements by css selector match.
when no match is found, it will retry for <timeout> seconds (default: 10), so
this is also suitable to use as wait condition.

calling `await page` will do a lot of stuff under the hood, and ensures all references
## await [`Tab`](#nodriver.Tab)

calling `await tab` will do a lot of stuff under the hood, and ensures all references
are up to date. also it allows for the script to “breathe”, as it is oftentime faster than your browser or
webpage. So whenever you get stuck and things crashes or element could not be found, you should probably let
it “breathe” by calling `await page` and/or `await page.sleep()`

also, it’s ensuring `url` will be updated to the most recent one, which is quite important in some
other methods.

### Using other and custom CDP commands

using the included cdp module, you can easily craft commands, which will always return an generator object.
this generator object can be easily sent to the [`send()`](#nodriver.Tab.send) method.

## [`send()`](#nodriver.Tab.send)

this is probably THE most important method, although you won’t ever call it, unless you want to
Expand Down
Loading

0 comments on commit 0285a7c

Please sign in to comment.