Skip to main content

Selenium plugin to manage shadow DOM elements on web page.

Project description

pyshadow

Selenium plugin to manage multi level shadow DOM elements on web page.

Build Status codecov PyPI version shields.io License

Shadow DOM:

Shadow DOM is a web standard that offers component style and markup encapsulation. It is a critically important piece of the Web Components story as it ensures that a component will work in any environment even if other CSS or JavaScript is at play on the page.

Custom HTML Tags:

Custom HTML tags can't be directly identified with selenium tools. Using this plugin you can handle any custom HTML tags.

Problem Statement:

  • You have already developed your web-based automation framework in java selenium. Your frontend application uses Polymer that uses shadow dom. Selenium doesn't provide any way to deal with shadow-dom elements.
  • Your application page contains custom HTML tags that can't be identified directly using selenium.

Solution:

You can use this plugin by adding jar file or by including maven dependency in your java selenium project.

How it works:

Methods:

find_element(str css_selector) : use this method if want single element from DOM

find_elements(str css_selector) : use this if you want to find all elements from DOM

find_element(object parent, str css_selector) : use this if you want to find a single elements from parent object DOM

find_elements(object parent, str css_selector) : use this if you want to find all elements from parent object DOM

set_implicit_wait(int seconds) : use this method for implicit wait

set_explicit_wait(int seconds, int polling_time) raise Exception : use this method for explicit wait

get_shadow_element(object parent,str css_selector) : use this if you want to find a single element from parent DOM

get_all_shadow_element(object parent, str css_selector) : use this if you want to find all elements from parent DOM

get_parent_element(object element) : use this to get the parent element if web element.

get_child_elements(object parent) : use this to get all the child elements of parent element.

get_sibling_elements(object element) : use this to get all adjacent (sibling) elements.

get_sibling_element(object element, str css_selector) : use this to get adjacent(sibling) element using css selector.

get_next_sibling_element(object element) : use this to get next adjacent(sibling) element.

get_previous_sibling_element(object element) : use this to get previous adjacent(sibling) element..

is_visible(object element) : use this if you want to find visibility of element

is_checked(object element) : use this if you want to check if checkbox is selected

is_disabled(object element) : use this if you want to check if element is disabled

get_attribute(object element, str attribute) : use this if you want to get attribute like aria-selected and other custom attributes of elements.

select_checkbox(str label) : use this to select checkbox element using label.

select_checkbox(object parent, str label) : use this to select checkbox element using label.

select_radio(str label) : use this to select radio element using label.

select_radio(object parent, str label) : use this to select radio element from parent DOM using label.

select_dropdown(str label) : use this to select dropdown list item using label (use this if only one dropdown is present or loaded on UI).

select_dropdown(object parent, str label) : use this to select dropdown list item from parent DOM using label.

scroll_to(object element) : use this to scroll to web element.

How to use this plugin:

You will have to install this plugin from PyPi.

Maven

pip install pyshadow

Selector:

Examples:

for html tag <paper-tab title="Settings"> You can use this code in your framework to grab the paper-tab element Object.

from selenium import webdriver
from pyshadow.main import Shadow
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
shadow = Shadow(driver)
element = shadow.find_element("paper-tab[title='Settings']")
elements = shadow.find_elements("paper-tab[title='Settings']")
text = element.text

for html tag that resides under a shadow-root dom element <input title="The name of the employee"> You can use this code in your framework to grab the paper-tab element Object.

from selenium import webdriver
from pyshadow.main import Shadow
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
shadow = Shadow(driver)
element = shadow.find_element("input[title='The name of the employee']")
text = element.text

for html tag that resides under a shadow-root dom element

<properties-page id="settingsPage"> 
  <textarea id="textarea">
</properties-page>

You can use this code in your framework to grab the textarea element Object.

from selenium import webdriver
from pyshadow.main import Shadow
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
shadow = Shadow(driver)
element = shadow.find_element("properties-page#settingsPage>textarea#textarea")
text = element.text

Wait: Implicit and Explicit

If you want to use wait to synchronize your scripts then you should use the implicit or explicit wait feature.

  • For Implicit wait, you can use shadow.set_implicit_wait(int seconds) method.

  • For Explicit wait, you can use shadow.set_explicit_wait(int seconds, int pollingTime) method.

  • In Implicit wait, the driver will wait for at least n seconds as set in shadow.set_implicit_wait(n).

  • In Explicit wait, the driver will wait for at max n seconds as set in shadow.set_implicit_wait(n,m). In between driver will check for presence of WebElement every m seconds.

    Note: > is used to combine multi level dom structure. So you can combine 5 levels of dom. If you want some more level modify the script and ready to rock.

    Documentation Link

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyshadow-0.0.5.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

pyshadow-0.0.5-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file pyshadow-0.0.5.tar.gz.

File metadata

  • Download URL: pyshadow-0.0.5.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.6

File hashes

Hashes for pyshadow-0.0.5.tar.gz
Algorithm Hash digest
SHA256 f10c1760985e8e7bad8091d433c7865a51cf2dbec1f5e950bd5d6bd9e3361c3f
MD5 a3388591a9537e68f838cb7cf9aaf72a
BLAKE2b-256 71cfa54f5f9e92fe96ca07d8c958b17510905d8a845f95037125eb5fdc2a86c1

See more details on using hashes here.

File details

Details for the file pyshadow-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: pyshadow-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.6

File hashes

Hashes for pyshadow-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7cde8543a5e3a152895005282695b2cd4eb353bd14424463a257508f09cd2171
MD5 803d035e55e4395641963bde645ad21b
BLAKE2b-256 cbb2a886453127d9dd8890b7c04f816c218c438d3cb37c4f9a6c6406277900a9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page