Constants
This section documents all constants, enums, and configuration values used throughout Pydoll.
pydoll.constants
QWERTY_NEIGHBORS
module-attribute
QWERTY_NEIGHBORS = {'1': ['2', 'q'], '2': ['1', '3', 'q', 'w'], '3': ['2', '4', 'w', 'e'], '4': ['3', '5', 'e', 'r'], '5': ['4', '6', 'r', 't'], '6': ['5', '7', 't', 'y'], '7': ['6', '8', 'y', 'u'], '8': ['7', '9', 'u', 'i'], '9': ['8', '0', 'i', 'o'], '0': ['9', '-', 'o', 'p'], '-': ['0', '=', 'p', '['], '=': ['-', '[', ']'], 'q': ['1', '2', 'w', 'a', 's'], 'w': ['q', '2', '3', 'e', 'a', 's', 'd'], 'e': ['w', '3', '4', 'r', 's', 'd', 'f'], 'r': ['e', '4', '5', 't', 'd', 'f', 'g'], 't': ['r', '5', '6', 'y', 'f', 'g', 'h'], 'y': ['t', '6', '7', 'u', 'g', 'h', 'j'], 'u': ['y', '7', '8', 'i', 'h', 'j', 'k'], 'i': ['u', '8', '9', 'o', 'j', 'k', 'l'], 'o': ['i', '9', '0', 'p', 'k', 'l', ';'], 'p': ['o', '0', '-', '[', 'l', ';', "'"], '[': ['p', '-', '=', ']', ';', "'"], ']': ['[', '=', "'"], 'a': ['q', 'w', 's', 'z', 'x'], 's': ['q', 'w', 'e', 'a', 'd', 'z', 'x', 'c'], 'd': ['w', 'e', 'r', 's', 'f', 'x', 'c', 'v'], 'f': ['e', 'r', 't', 'd', 'g', 'c', 'v', 'b'], 'g': ['r', 't', 'y', 'f', 'h', 'v', 'b', 'n'], 'h': ['t', 'y', 'u', 'g', 'j', 'b', 'n', 'm'], 'j': ['y', 'u', 'i', 'h', 'k', 'n', 'm', ','], 'k': ['u', 'i', 'o', 'j', 'l', 'm', ',', '.'], 'l': ['i', 'o', 'p', 'k', ';', ',', '.', '/'], ';': ['o', 'p', '[', 'l', "'", '.', '/'], "'": ['p', '[', ']', ';', '/'], 'z': ['a', 's', 'x'], 'x': ['z', 'a', 's', 'd', 'c'], 'c': ['x', 's', 'd', 'f', 'v'], 'v': ['c', 'd', 'f', 'g', 'b'], 'b': ['v', 'f', 'g', 'h', 'n'], 'n': ['b', 'g', 'h', 'j', 'm'], 'm': ['n', 'h', 'j', 'k', ','], ',': ['m', 'j', 'k', 'l', '.'], '.': [',', 'k', 'l', ';', '/'], '/': ['.', 'l', ';', "'"], ' ': ['c', 'v', 'b', 'n', 'm']}
By
Bases: str, Enum
PageLoadState
ScrollPosition
Scripts
ELEMENT_VISIBLE
class-attribute
instance-attribute
ELEMENT_VISIBLE = "\n function() {\n const rect = this.getBoundingClientRect();\n return (\n rect.width > 0 && rect.height > 0\n && getComputedStyle(this).visibility !== 'hidden'\n && getComputedStyle(this).display !== 'none'\n )\n }\n "
ELEMENT_ON_TOP
class-attribute
instance-attribute
ELEMENT_ON_TOP = '\n function() {\n const rect = this.getBoundingClientRect();\n const x = rect.x + rect.width / 2;\n const y = rect.y + rect.height / 2;\n const elementFromPoint = document.elementFromPoint(x, y);\n if (!elementFromPoint) {\n return false;\n }\n return elementFromPoint === this || this.contains(elementFromPoint);\n }\n '
ELEMENT_INTERACTIVE
class-attribute
instance-attribute
ELEMENT_INTERACTIVE = "\n function() {\n const style = window.getComputedStyle(this);\n const rect = this.getBoundingClientRect();\n if (\n rect.width <= 0 ||\n rect.height <= 0 ||\n style.visibility === 'hidden' ||\n style.display === 'none' ||\n style.pointerEvents === 'none'\n ) {\n return false;\n }\n const x = rect.x + rect.width / 2;\n const y = rect.y + rect.height / 2;\n const elementFromPoint = document.elementFromPoint(x, y);\n if (!elementFromPoint || (elementFromPoint !== this && !this.contains(elementFromPoint))) {\n return false;\n }\n if (this.disabled) {\n return false;\n }\n return true;\n }\n "
CLICK
class-attribute
instance-attribute
CLICK = "\n function(){\n clicked = false;\n this.addEventListener('click', function(){\n clicked = true;\n });\n this.click();\n return clicked;\n }\n "
CLICK_OPTION_TAG
class-attribute
instance-attribute
CLICK_OPTION_TAG = "\n function() {\n var select = this && this.parentElement ? this.parentElement.closest('select') : null;\n if (!select) { return false; }\n for (var i = 0; i < select.options.length; i++) {\n select.options[i].selected = false;\n }\n this.selected = true;\n select.value = this.value;\n select.dispatchEvent(new Event('input', { bubbles: true }));\n select.dispatchEvent(new Event('change', { bubbles: true }));\n return true;\n }\n "
BOUNDS
class-attribute
instance-attribute
FIND_RELATIVE_XPATH_ELEMENT
class-attribute
instance-attribute
FIND_RELATIVE_XPATH_ELEMENT = '\n function() {\n return document.evaluate(\n "{escaped_value}", this, null,\n XPathResult.FIRST_ORDERED_NODE_TYPE, null\n ).singleNodeValue;\n }\n '
FIND_XPATH_ELEMENT
class-attribute
instance-attribute
FIND_XPATH_ELEMENT = '\n var element = document.evaluate(\n "{escaped_value}", document, null,\n XPathResult.FIRST_ORDERED_NODE_TYPE, null\n ).singleNodeValue;\n element;\n '
FIND_RELATIVE_XPATH_ELEMENTS
class-attribute
instance-attribute
FIND_RELATIVE_XPATH_ELEMENTS = '\n function() {\n var elements = document.evaluate(\n "{escaped_value}", this, null,\n XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null\n );\n var results = [];\n for (var i = 0; i < elements.snapshotLength; i++) {\n results.push(elements.snapshotItem(i));\n }\n return results;\n }\n '
FIND_XPATH_ELEMENTS
class-attribute
instance-attribute
FIND_XPATH_ELEMENTS = '\n var elements = document.evaluate(\n "{escaped_value}", document, null,\n XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null\n );\n var results = [];\n for (var i = 0; i < elements.snapshotLength; i++) {\n results.push(elements.snapshotItem(i));\n }\n results;\n '
QUERY_SELECTOR
class-attribute
instance-attribute
RELATIVE_QUERY_SELECTOR
class-attribute
instance-attribute
QUERY_SELECTOR_ALL
class-attribute
instance-attribute
RELATIVE_QUERY_SELECTOR_ALL
class-attribute
instance-attribute
RELATIVE_QUERY_SELECTOR_ALL = '\n function() {\n return this.querySelectorAll("{selector}");\n }\n '
GET_TEXT_BY_XPATH
class-attribute
instance-attribute
GET_TEXT_BY_XPATH = '\n (() => {\n const node = document.evaluate(\n "{escaped_value}",\n document,\n null,\n XPathResult.FIRST_ORDERED_NODE_TYPE,\n null\n ).singleNodeValue;\n return node ? (node.textContent || "") : "";\n })()\n '
GET_TEXT_BY_CSS
class-attribute
instance-attribute
GET_TEXT_BY_CSS = '\n (() => {\n const el = document.querySelector("{selector}");\n return el ? (el.textContent || "") : "";\n })()\n '
GET_PARENT_NODE
class-attribute
instance-attribute
GET_CHILDREN_NODE
class-attribute
instance-attribute
GET_CHILDREN_NODE = '\n function() {{\n function getChildrenUntilDepth(element, maxDepth, tagFilter = [], currentDepth = 1)\n {{\n if (currentDepth > maxDepth) return [];\n\n const children = Array.from(element.children);\n let filtered = tagFilter.length === 0\n ? children\n : children.filter(child => tagFilter.includes(child.tagName.toLowerCase()));\n\n let allDescendants = [...filtered];\n\n for (let child of children)\n {{\n allDescendants.push(\n ...getChildrenUntilDepth(child, maxDepth, tagFilter, currentDepth + 1)\n );\n }}\n\n return allDescendants;\n }}\n\n return getChildrenUntilDepth(this, {max_depth}, {tag_filter});\n }}\n '
GET_SIBLINGS_NODE
class-attribute
instance-attribute
GET_SIBLINGS_NODE = '\n function() {{\n function getSiblingsUntilDepth(element, tagFilter = [])\n {{\n const parent = element.parentElement;\n const siblings = Array.from(parent.children);\n let filtered = tagFilter.length === 0\n ? siblings.filter(child => child !== element)\n : siblings.filter(child =>\n tagFilter.includes(child.tagName.toLowerCase()) && child !== element);\n\n let allDescendants = [...filtered];\n\n return allDescendants;\n }}\n\n return getSiblingsUntilDepth(this, {tag_filter});\n }}\n '
MAKE_REQUEST
class-attribute
instance-attribute
MAKE_REQUEST = '\n(async function() {{\n async function makeRequest(url, options) {{\n try {{\n const response = await fetch(url, options, {{\n credentials: \'include\',\n }});\n const headers = {{}};\n response.headers.forEach((value, key) => {{\n headers[key] = value;\n }});\n\n // Extract cookies from set-cookie header\n const cookies = document.cookie;\n let text = await response.text();\n const possiblePrefixes = [")]}}\'\\n", ")]}}\'\\n", ")]}}\\n"];\n for (let prefix of possiblePrefixes) {{\n if (text.startsWith(prefix)) {{\n text = text.substring(prefix.length);\n break;\n }}\n }}\n let content, jsonData;\n const contentType = response.headers.get(\'content-type\') || \'\';\n\n if (contentType.includes(\'application/json\')) {{\n try {{\n jsonData = JSON.parse(text);\n text = JSON.stringify(jsonData);\n }} catch (e) {{\n jsonData = null;\n // Keep original text if parsing fails\n }}\n content = new TextEncoder().encode(text).buffer;\n }} else {{\n // For non-JSON, keep original text handling\n content = new TextEncoder().encode(text).buffer;\n jsonData = null;\n }}\n\n return {{\n status: response.status,\n ok: response.ok,\n url: response.url,\n headers: headers,\n cookies: cookies,\n content: Array.from(new Uint8Array(content)),\n text: text,\n json: jsonData\n }};\n }} catch (error) {{\n return {{\n error: error.toString(),\n status: 0\n }};\n }}\n }}\n\n const url = {url};\n const options = {options};\n return await makeRequest(url, options);\n}})();\n'
SCROLL_BY
class-attribute
instance-attribute
SCROLL_BY = "\nnew Promise((resolve) => {{\n const behavior = '{behavior}';\n if (behavior === 'auto') {{\n window.scrollBy({{\n {axis}: {distance},\n behavior: 'auto'\n }});\n resolve();\n }} else {{\n const onScrollEnd = () => {{\n window.removeEventListener('scrollend', onScrollEnd);\n resolve();\n }};\n window.addEventListener('scrollend', onScrollEnd);\n window.scrollBy({{\n {axis}: {distance},\n behavior: 'smooth'\n }});\n setTimeout(() => {{\n window.removeEventListener('scrollend', onScrollEnd);\n resolve();\n }}, 2000);\n }}\n}});\n"
SCROLL_TO_TOP
class-attribute
instance-attribute
SCROLL_TO_TOP = "\nnew Promise((resolve) => {{\n const behavior = '{behavior}';\n if (behavior === 'auto') {{\n window.scrollTo({{\n top: 0,\n behavior: 'auto'\n }});\n resolve();\n }} else {{\n const onScrollEnd = () => {{\n window.removeEventListener('scrollend', onScrollEnd);\n resolve();\n }};\n window.addEventListener('scrollend', onScrollEnd);\n window.scrollTo({{\n top: 0,\n behavior: 'smooth'\n }});\n setTimeout(() => {{\n window.removeEventListener('scrollend', onScrollEnd);\n resolve();\n }}, 2000);\n }}\n}});\n"
SCROLL_TO_BOTTOM
class-attribute
instance-attribute
SCROLL_TO_BOTTOM = "\nnew Promise((resolve) => {{\n const behavior = '{behavior}';\n if (behavior === 'auto') {{\n window.scrollTo({{\n top: document.body.scrollHeight,\n behavior: 'auto'\n }});\n resolve();\n }} else {{\n const onScrollEnd = () => {{\n window.removeEventListener('scrollend', onScrollEnd);\n resolve();\n }};\n window.addEventListener('scrollend', onScrollEnd);\n window.scrollTo({{\n top: document.body.scrollHeight,\n behavior: 'smooth'\n }});\n setTimeout(() => {{\n window.removeEventListener('scrollend', onScrollEnd);\n resolve();\n }}, 2000);\n }}\n}});\n"
GET_SCROLL_Y
class-attribute
instance-attribute
GET_REMAINING_SCROLL_TO_BOTTOM
class-attribute
instance-attribute
GET_REMAINING_SCROLL_TO_BOTTOM = '\n(function() {\n const scrollHeight = Math.max(\n document.body.scrollHeight,\n document.documentElement.scrollHeight\n );\n const clientHeight = window.innerHeight;\n const scrollTop = window.scrollY || window.pageYOffset || 0;\n return Math.max(0, scrollHeight - clientHeight - scrollTop);\n})()\n'
GET_VIEWPORT_CENTER
class-attribute
instance-attribute
INSERT_TEXT
class-attribute
instance-attribute
INSERT_TEXT = "\n function() {\n const el = this;\n const text = arguments[0];\n\n // Standard input/textarea\n if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA') {\n const start = el.selectionStart || el.value.length;\n const end = el.selectionEnd || el.value.length;\n const before = el.value.substring(0, start);\n const after = el.value.substring(end);\n el.value = before + text + after;\n el.selectionStart = el.selectionEnd = start + text.length;\n el.dispatchEvent(new Event('input', { bubbles: true }));\n el.dispatchEvent(new Event('change', { bubbles: true }));\n return true;\n }\n\n // ContentEditable elements\n if (el.isContentEditable) {\n el.focus();\n const selection = window.getSelection();\n const range = selection.getRangeAt(0);\n range.deleteContents();\n const textNode = document.createTextNode(text);\n range.insertNode(textNode);\n range.setStartAfter(textNode);\n range.setEndAfter(textNode);\n selection.removeAllRanges();\n selection.addRange(range);\n el.dispatchEvent(new Event('input', { bubbles: true }));\n return true;\n }\n\n return false;\n }\n "
IS_EDITABLE
class-attribute
instance-attribute
IS_EDITABLE = "\n function() {\n const el = this;\n\n // Check standard input elements\n if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA') {\n return !el.disabled && !el.readOnly;\n }\n\n // Check contenteditable (including inherited)\n let current = el;\n while (current) {\n if (current.isContentEditable) {\n return true;\n }\n current = current.parentElement;\n }\n\n return false;\n }\n "
Key
Bases: tuple[str, int], Enum
BrowserType
TypoType
Bases: str, Enum
Types of realistic typing errors.