Skip to content

Commit

Permalink
Added methods to get child and parent element
Browse files Browse the repository at this point in the history
  • Loading branch information
sukgu committed Jun 2, 2019
1 parent d0c4d79 commit 8a6e949
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ You can use this plugin by adding jar file or by including maven dependency in y

`List<WebElement> getAllShadowElement(WebElement parent,String selector)` : use this if you want to find all elements from parent DOM

`WebElement getParentElement(WebElement element)` : use this to get the parent element if web element.

`List<WebElement> getChildElements(WebElement parent)` : use this to get all the child elements of parent element.

`boolean isVisible(WebElement element)` : use this if you want to find visibility of element

`boolean isChecked(WebElement element)` : use this if you want to check if checkbox is selected
Expand Down Expand Up @@ -61,17 +65,17 @@ You can use this plugin by adding jar file or by including maven dependency in y
<dependency>
<groupId>io.github.sukgu</groupId>
<artifactId>automation</artifactId>
<version>0.0.4</version>
<version>0.0.5</version>
<dependency>
```

**Gradle**
```
implementation 'io.github.sukgu:automation:0.0.4'
implementation 'io.github.sukgu:automation:0.0.5'
```


You can download the jar file from repository http://central.maven.org/maven2/io/github/sukgu/automation/0.0.4/automation-0.0.4.jar
You can download the jar file from repository http://central.maven.org/maven2/io/github/sukgu/automation/0.0.5/automation-0.0.5.jar

## Selector:
###### Examples:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.github.sukgu</groupId>
<artifactId>automation</artifactId>
<version>0.0.4</version>
<version>0.0.5</version>

<name>automation</name>
<description>This project automates shadow-dom elements using java selenium</description>
Expand Down
18 changes: 17 additions & 1 deletion resources/querySelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,30 @@ var getAttribute = function getAttribute(object,attribute) {
};

var isVisible = function isVisible(object) {
var visible = object.widthOffset();
var visible = object.offsetWidth;
if(visible>0) {
return true;
} else {
return false;
}
};

var getParentElement = function getParentElement(object) {
if(object.parentNode.nodeName=="#document-fragment") {
return object.children;
} else {
return object.childElements();
}
};

var getChildElements = function getChildElements(object) {
if(object.nodeName=="#document-fragment") {
return object.parentNode.host;
} else {
return object.parentElement;
}
};

var isChecked = function isChecked(object) {
return object.checked;
};
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/io/github/sukgu/Shadow.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ public List<WebElement> getAllShadowElement(WebElement parent,String selector) {
}
return elements;
}

public WebElement getParentElement(WebElement element) {
return (WebElement) executerGetObject("return getParentElement(arguments[0]);", element);
}

@SuppressWarnings("unchecked")
public List<WebElement> getChildElements(WebElement parent) {
List<WebElement> elements = null;
Object object = executerGetObject("return getChildElements(arguments[0]);", parent);
if(object!=null && object instanceof List<?>) {
elements = (List<WebElement>) object;
}
return elements;
}

public boolean isVisible(WebElement element) {
return (Boolean) executerGetObject("return isVisible(arguments[0]);", element);
Expand Down

0 comments on commit 8a6e949

Please sign in to comment.