Hey Tatu (@aaltat)
Could you give me a hint how to add new locator strategies in a Selenium Plugin?
This code works but the driver instance that is handed over is a bit weird.
This ShadowDomFinder inherits the original one.
i could also just add the new finder method to the self._strategies
but i was not sure.
could you maybe give a minimum example?
this _find_by_dim
is just a dummy.
from SeleniumLibrary.base import LibraryComponent
from SeleniumLibrary.locators import ElementFinder
class ShadowDomFinder(ElementFinder):
def __init__(self, ctx):
ElementFinder.__init__(self, ctx)
self.register('dim',self._find_by_dim, True)
def _find_by_dim(self, driver, criteria, tag, constraints, parent=None):
self._disallow_webelement_parent(parent)
result = self.driver.execute_script("return %s;" % criteria)
if result is None:
return []
if not isinstance(result, list):
result = [result]
return self._filter_elements(result, tag, constraints)
class ShadowDom(LibraryComponent):
def __init__(self, ctx):
LibraryComponent.__init__(self, ctx)
self.element_finder = ShadowDomFinder(ctx)
Robot Code:
*** Settings ***
Library SeleniumLibrary plugins=ShadowDom
*** Test Cases ***
test
Open Browser browser=chrome
Go To chrome://settings/
${text}= Get Text dim:document.querySelector("body > settings-ui").shadowRoot.querySelector("#main").shadowRoot.querySelector("settings-basic-page").shadowRoot.querySelector("#basicPage > settings-section:nth-child(3) > settings-people-page").shadowRoot.querySelector("#edit-profile > div")
[Teardown] Close All Browsers