Giter VIP home page Giter VIP logo

sukgu / shadow-automation-selenium Goto Github PK

View Code? Open in Web Editor NEW
103.0 13.0 33.0 84 KB

This project focuses on automation of multi-level shadow root dom using java selenium. You can embed this plugin in your java selenium project.

Home Page: https://search.maven.org/artifact/io.github.sukgu/automation

License: Apache License 2.0

JavaScript 21.17% Java 77.06% HTML 1.74% CSS 0.04%
selenium selenium-webdriver selenium-java shadow-dom polymer automation testing-tools custom-elements custom-tag

shadow-automation-selenium's People

Contributors

kelunik avatar sergueik avatar sukgu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shadow-automation-selenium's Issues

Add wait methods on shadow objects

This feature will add wait methods on shadow objects
Currently, we are not able to use selenium implicit and explicit waits on shadow objects. This feature will methods like selenium that will work for shadow objects.

Additional context
After this fix user will be able to use shadow objects waits in the same way they use selenium waits and this will work for both normal DOM elements and shadow DOM elements.

findElementsByXPath methods returning duplicate elements

URL: https://www.bedbathandbeyond.com/store/s/dresser

Shadow shadow = new Shadow(driver);
List we = shadow.findElementsByXPath("//a[@ROLE='listitem']");
for (WebElement w : we) {
System.out.println(w.getText());
}

The count of WebElements returned should be the same as present in DOM and UI. But using methods findElementsByXPath it returns around 63 webelements(7 elements repeated 9 times). This works fine using css selector findElements method. Facing issue only with findElementsByXPath.

image

FindElementsByXpath:
image

css: findElements
image

Browser: Chrome
Version: 89.0.4389.90
OS: Windows 10

Unable to use ">" for getting direct child element.

Describe the bug
With the getObject and getAllObject methods in querySelector.js, > symbol is removed in splitting, but never processed back and won't take effect. This causes all related Shadow.findElement(s) behaviors to be malfunctioning. See the following example:

To Reproduce
Steps to reproduce the behavior:

  1. Consider a following DOM:
<html>
  <div id="a">
      <div id="b">
         <div id="c"></div>
      </div>
      <div id="d"></div>
  </div>
  <script src="querySelector.js"></script>
</html>
  1. run getAllObject("div#a > div") in the console.
  2. Actual result is [<div id="b">, <div id="c">, <div id="d">], but #c is not a direct child of #a

Expected behavior
Expected result should be [<div id="b">, <div id="d">]

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS 13.6.4
  • Browser: Chrome 123 / Safari 17.3.1

Additional context

const multiLevelSelectors = splitByCharacterUnlessQuoted(selector, '>');

I don't understand why > is used to process multi-level DOM.
For functional, this is not needed at all, since without splitting, the script still works fine for piercing through multi-level shadow roots.
For performance, if we have to use some symbol to reduce the max size of possible elements cached in the allElements array, & would be a much better choice considering only one character is allowed in splitByCharacterUnlessQuoted.

getParentElement does not return parent element

getParentElement does not return parent element

Steps:

  1. First find the child element using findElement
  2. Use the getParentElement by passing the element found in first step

Expected: Should return the parent element

Actual: Throwing an exception:
org.openqa.selenium.JavascriptException: javascript error: object.childElements is not a function
(Session info: chrome=75.0.3770.100)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'RST-QAPURU', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 74.0.3729.6 (255758eccf3d24..., userDataDir: C:\Users\PARAMA~1\AppData\L...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:13202}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), rotatable: false, setWindowRect: true, strictFileInteractability: false, takesHeapSnapshot: true, takesScreenshot: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 75.0.3770.100, webStorageEnabled: true, webdriver.remote.sessionid: 7669a2eb87d2be4100635adcde4...}
Session ID: 7669a2eb87d2be4100635adcde4d021d

image

Getting FileNotFoundException

When trying to get a shadow dom element, Im getting below exception in Shadow.class file in line 83
java.io.FileNotFoundException: resource\querySelector.js (The system cannot find the path specified)

I have added the below dependency as well


io.github.sukgu
automation
0.0.1

Not sure whether Im missing anything here

There is no helper method for scrolling to the exact element in the webpage

There is no helper method for scrolling to the exact element in the webpage

Scenario:
When the element is located down/up where user has to scroll to the element to perform action on that

I need a helper method where i specify the Webelement css selector/webelement as a parameter
this should scroll the webpage and find for the element and take the control to that element. If element found return true else return false

shadow method for xpath throwing error when using pipe separator for 2 xpaths

Xpath used: //div[@id='dskMenuLevel1']//button[@data-dsk-click='categories'] | //div[@id='dskMenuLevel1']//button[@data-dsk-click='Categories']

Error Message:
invalid element state: Failed to execute 'evaluate' on 'Document': The string './/button[@data-dsk-click='categories'] | ' is not a valid XPath expression.

Can't we use multiple xpaths in shadow library methods by adding pipe symbol as separator?

I'm gettinf error while passing driver itself

WebDriver driver;
System.setProperty("webdriver.chrome.driver", "C:\Users\DELL\Downloads\chromedriver_win32 (5)\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("chrome://settings/privacy");
Thread.sleep(3000);

    Shadow shadow = new Shadow(driver);

using FindBy

Hi, can you show how to find elements using PageFactory with POM?
Page Factory annotations (@findby)

Getting NoSuchElementException when trying to run on linux remote instance via jenkins

Describe the bug
When i try to run the same code using Local machine(Mac+GoogleChrome(103.0.5060.114) do not gets any error but when trying to run using pipeline jenkins project with linux instance and chrome version - 100.0.4896.75 (os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.68-62.173.amzn2.x86_64', java.version: '1.8.0_121') getting "NoElementFound" despite waiting long as explicit wait.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Getting css not found always when implicit or explicit wait is not set.

Describe the bug
If we don't set implicit or explicit wait then the findElement method always throws ElementNotVisibleException

To Reproduce
Steps to reproduce the behavior:

  1. Use findElement method without setting wait conditions,

Expected behavior
It should work fine if the page is loaded.

Don't package selenium dependency in jar

Currently, we are packaging selenium dependencies in the packaged jar that sometimes don't work well with different selenium versions. Removing this will let users use their own selenium dependency.
This will also fix the Katalon dependency problem.

Use XPath to find shadow elements.

This will serve the purpose to find the shadow elements using XPath. This will create a base for #18

var xpathResult = document.evaluate(
  xpathExpression,
  contextNode,
  namespaceResolver,
  resultType,
  result
);

findElementByXPath giving ElementNotVisibleException, however findElementsByXPath returning one element

Visit URL: https://em02-www.bbbyapp.com/store/product/keurig-k-caf-eacute-special-edition-single-serve-coffee-latte-amp-cappuccino-maker/5211803?keyword=5211803&web3feo

Steps to Reproduce:
Click Heart icon on Product image
click "Create IdeaBoard" on popup
Enter some random text in Board Name
click Save

Now in below line we will get ElementNotVisibleException Exception if we don't add a browser refresh before it. We are trying to find 'Sign in' link present in Header
shadow.findElementByXPath("//div[contains(@Class, 'dskAcctCont')]//a[@id = 'accountlink']");

Error Message:
org.openqa.selenium.ElementNotVisibleException: Element with XPath //div[contains(@Class, 'dskAcctCont')]//a[@id = 'accountlink'] is not present on screen

Screenshot (137)
Screenshot (136)

getAllObject fails if element is not present

It fails with the following error:

org.openqa.selenium.JavascriptException:
javascript error: Cannot read property 'shadowRoot' of undefined

Reading the code, it can't work correctly.

parent = querySelectorDeep(multiLevelSelectors[0]);
if (parent === undefined) {
    parent = querySelectorDeep(multiLevelSelectors[0]).shadowRoot
}

Here it queries for querySelectorDeep(multiLevelSelectors[0]), if the result is undefined, it does the exact same thing again, but tries to access .shadowRoot afterwards, which obviously fails.

Please provide HTML code to your Java examples

Hi Sushil,
Thank you for providing this tool. It looks very promising to solve my current issue with a shadow dom. Could you please also provide the HTML code to which your Java code snittlets from the documentation are applied? This would help me to understand your solution better. Just a suggestion.
Kind regards
-- Frank

Maven/Gradle latest version 0.1.3 does not include the implicit/Explicit wait methods

When setting up the project either using pom maven - or build gradle files, the latest version there (0.1.3) does not include the implicit and explicit wait methods

Can you push the latest master artifact there as well, please?

Sceenshot of the Shadow Class downloaded from maven/gradle. The first few lines should contain:
private int implicitWait = 0;
private int explicitWait = 0;
private int pollingTime = 0;
Screenshot 2022-01-20 at 17 02 53
Kind regards,
Matei

Indexing in xpath is not working

The xpath doesn't allow indexing like below:
(//h1[@Class='Heading'])[1]
Getting Exception
invalid element state: Failed to execute 'evaluate' on 'Document': The string '(//h1[@Class='Heading'])[1]' is not a valid XPath expression.

Add xpath locators to project or how to search by text

Hello Sushil,
Now we are able to use only css locators but they can't search by text. I tried something like "tag[innerText='text']", "tag[text='text']" and several other variants but they don't work. Do you have any workarounds to search components by text?

CSS with double quotes having single quotes inside not working.

Describe the bug
If we have a CSS like shadow.find_element("div[label='QA']") doesn't work and throws error. The same works fine when we have CSS like shadow.find_element('div[label="QA"]')

To Reproduce
Steps to reproduce the behavior:

  1. Write code to find an element with an attribute value like shadow.find_element("div[label='QA']")
  2. Run the code
  3. See error

Expected behavior
It should work fine for single quotes and double quotes both.

Find element returns null when there multiple level of >

Find element returns null when there multiple level:

Below line of code return null though element exists:
WebElement textboxCollection3 = shadow.findElement(textboxCollection2,"pebble-textbox>paper-input>paper-input-container>iron-input>input");

Nullpointerexception when calling the Shadow constructor

When trying to create an instance of shadow with the Shadow(WebDriver driver) constructor, i get this error:

Exception in thread "main" java.lang.NullPointerException
at java.base/java.io.Reader.(Reader.java:167)
at java.base/java.io.InputStreamReader.(InputStreamReader.java:72)
at io.github.sukgu.Shadow.convertJStoText(Shadow.java:124)
at io.github.sukgu.Shadow.(Shadow.java:42)
at sed.main(sed.java:109)

To Reproduce

  1. Open a WebBrowser with debug port open (test was done with chromium based browser)
  2. connect selenium to the browser. ( i am using selenium 4.0.0 something as i forked selenium and didn't wanted to migrate my code when it still works)
  3. Validate the driver works by opening a site or something.
  4. (try to) create a Shadow instance with the driver object.

Desktop (please complete the following information):

  • OS: linux mint version: the most recent one
  • Chrome, Chromium.. doesn't really matter; tested valid on Google Chrome Version 92.0.4515.159 (Official Build) (64-bit)
  • Selenium 4.0.0 beta 2 fork (fork only adds some methods, doesn't breaks any functionality)

test Code snippets
in bash:
google-chrome --remote-debugging-port=9001
in java

`
import io.github.sukgu.Shadow
;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.interactions.Actions;

import org.openqa.selenium.chrome.ChromeOptions;

import org.openqa.selenium.JavascriptExecutor;

public class test {
	public static WebDriver driver;
	public static JavascriptExecutor js;
	public static Actions actions;

	public static void main(String[] args) {
		ChromeOptions options = new ChromeOptions();

		System.setProperty("webdriver.chrome.driver", "webdivers/chromedriver"); 

		//--remote-debugging-port=9000
		options.setExperimentalOption("debuggerAddress","localhost:9001");


		driver = new ChromeDriver(options);
		js = (JavascriptExecutor) driver;
		actions = new Actions(driver);
		
 		// validates if the Webdriver actually controls the browser
		driver.get("chrome://settings/");

		Shadow shadow = new Shadow(driver);
	}
}`

console output:

Starting ChromeDriver 92.0.4515.107 (87a818b10553a07434ea9e2b6dccf3cbe7895134-refs/branch-heads/4515@{#1634}) on port 12936
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Aug 24, 2021 11:30:22 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Aug 24, 2021 11:30:22 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 92, so returning the closest version found: 91
Aug 24, 2021 11:30:22 PM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found CDP implementation for version 92 of 91
Exception in thread "main" java.lang.NullPointerException
at java.base/java.io.Reader.(Reader.java:167)
at java.base/java.io.InputStreamReader.(InputStreamReader.java:72)
at io.github.sukgu.Shadow.convertJStoText(Shadow.java:124)
at io.github.sukgu.Shadow.(Shadow.java:42)
at test.main(test.java:36)

Implicit wait inside explicit

Hi there, you library is very useful, congratulations. However we noticed that test last too much when using it. We think it could be related to this implicit wait in the code. I have set the pollingTime up to 1 s. So in every findElement we have to wait, at least 1 second. This becomes unacceptable when we have 20 assertions we are adding 20 seconds to the execution. In our previous implementation assertions don't take more than 2 seconds.

Have you planned to remove this wait?

getChildElements helper method is throwing an error

getChildElements method is throwing an error, please find the error below:

org.openqa.selenium.JavascriptException: javascript error: object.childElements is not a function
(Session info: chrome=75.0.3770.100)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'RST-QAPURU', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 74.0.3729.6 (255758eccf3d24..., userDataDir: C:\Users\PARAMA~1\AppData\L...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:13934}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), rotatable: false, setWindowRect: true, strictFileInteractability: false, takesHeapSnapshot: true, takesScreenshot: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 75.0.3770.100, webStorageEnabled: true, webdriver.remote.sessionid: 2b30b4a0562ad8b3036b642ef6a...}
Session ID: 2b30b4a0562ad8b3036b642ef6a570e5

shadow-root type

Hi,

I was trying to use shadow-automation-selenium to get elements inside closed shadow-root, but without any luck.
I was wondering if this is supported in your framework?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.