Skip to content

Commit 3a55db0

Browse files
authored
Merge pull request #4 from xdev-software/develop
Release
2 parents 9a023e8 + f5dbfbf commit 3a55db0

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 1.0.2
2+
* ``ImprovedRemoteWebElement``
3+
* Make it possible to disable auto scroll
4+
* Don't throw an exception when scrolling into view is somehow not working
5+
* Improve logger initialization
6+
17
# 1.0.1
28
* Correctly declare ``software.xdev:testcontainers-selenium`` as scope ``test``
39

selenium-elements/src/main/java/software/xdev/selenium/elements/remote/ImprovedRemoteWebElement.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.openqa.selenium.ElementNotInteractableException;
1919
import org.openqa.selenium.WebDriver;
2020
import org.openqa.selenium.remote.RemoteWebElement;
21+
import org.slf4j.Logger;
2122
import org.slf4j.LoggerFactory;
2223

2324
import software.xdev.selenium.elements.CanFindElements;
@@ -34,13 +35,30 @@
3435
@SuppressWarnings("java:S2160")
3536
public class ImprovedRemoteWebElement extends RemoteWebElement implements CanFindElements
3637
{
37-
protected String waitForServerLoadToFinishFunction;
38+
protected Logger logger;
39+
protected final String waitForServerLoadToFinishFunction;
40+
protected boolean autoScrollIntoView = true;
3841

3942
public ImprovedRemoteWebElement(final String waitForServerLoadToFinishFunction)
4043
{
4144
this.waitForServerLoadToFinishFunction = waitForServerLoadToFinishFunction;
4245
}
4346

47+
public ImprovedRemoteWebElement withAutoScrollIntoView(final boolean autoScrollIntoView)
48+
{
49+
this.autoScrollIntoView = autoScrollIntoView;
50+
return this;
51+
}
52+
53+
protected Logger logger()
54+
{
55+
if(this.logger == null)
56+
{
57+
this.logger = LoggerFactory.getLogger(this.getClass());
58+
}
59+
return this.logger;
60+
}
61+
4462
@Override
4563
public WebDriver getWebDriver()
4664
{
@@ -57,8 +75,7 @@ public void click()
5775
}
5876
catch(final ElementNotInteractableException ex)
5977
{
60-
LoggerFactory.getLogger(this.getClass())
61-
.warn(
78+
this.logger().warn(
6279
"Element can't be clicked via UI - executing JS click. "
6380
+ "Please manually check if the element is accessible. "
6481
+ "If the element is accessible consider calling performJsClick directly.", ex);
@@ -94,9 +111,16 @@ public void prepareForOperation()
94111

95112
public void scrollIntoViewIfRequired()
96113
{
97-
if(!this.isDisplayed())
114+
try
115+
{
116+
if(this.autoScrollIntoView && !this.isDisplayed())
117+
{
118+
this.executeScript("arguments[0].scrollIntoView(true);", this);
119+
}
120+
}
121+
catch(final ElementNotInteractableException ex)
98122
{
99-
this.executeScript("arguments[0].scrollIntoView(true);", this);
123+
this.logger().warn("Element can't be scrolled into view", ex);
100124
}
101125
}
102126

@@ -115,8 +139,7 @@ public void waitForServerLoadToFinish()
115139
final Boolean retVal = (Boolean)this.executeScript(this.waitForServerLoadToFinishFunction);
116140
if(retVal == null)
117141
{
118-
LoggerFactory.getLogger(this.getClass())
119-
.warn("waitForLoadToFinishFunction returned null! It should either return true or false");
142+
this.logger().warn("waitForLoadToFinishFunction returned null! It should either return true or false");
120143
}
121144
finished = Boolean.TRUE.equals(retVal);
122145
}

0 commit comments

Comments
 (0)