Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.0.2
* ``ImprovedRemoteWebElement``
* Make it possible to disable auto scroll
* Don't throw an exception when scrolling into view is somehow not working
* Improve logger initialization

# 1.0.1
* Correctly declare ``software.xdev:testcontainers-selenium`` as scope ``test``

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.openqa.selenium.ElementNotInteractableException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import software.xdev.selenium.elements.CanFindElements;
Expand All @@ -34,13 +35,30 @@
@SuppressWarnings("java:S2160")
public class ImprovedRemoteWebElement extends RemoteWebElement implements CanFindElements
{
protected String waitForServerLoadToFinishFunction;
protected Logger logger;
protected final String waitForServerLoadToFinishFunction;
protected boolean autoScrollIntoView = true;

public ImprovedRemoteWebElement(final String waitForServerLoadToFinishFunction)
{
this.waitForServerLoadToFinishFunction = waitForServerLoadToFinishFunction;
}

public ImprovedRemoteWebElement withAutoScrollIntoView(final boolean autoScrollIntoView)
{
this.autoScrollIntoView = autoScrollIntoView;
return this;
}

protected Logger logger()
{
if(this.logger == null)
{
this.logger = LoggerFactory.getLogger(this.getClass());
}
return this.logger;
}

@Override
public WebDriver getWebDriver()
{
Expand All @@ -57,8 +75,7 @@ public void click()
}
catch(final ElementNotInteractableException ex)
{
LoggerFactory.getLogger(this.getClass())
.warn(
this.logger().warn(
"Element can't be clicked via UI - executing JS click. "
+ "Please manually check if the element is accessible. "
+ "If the element is accessible consider calling performJsClick directly.", ex);
Expand Down Expand Up @@ -94,9 +111,16 @@ public void prepareForOperation()

public void scrollIntoViewIfRequired()
{
if(!this.isDisplayed())
try
{
if(this.autoScrollIntoView && !this.isDisplayed())
{
this.executeScript("arguments[0].scrollIntoView(true);", this);
}
}
catch(final ElementNotInteractableException ex)
{
this.executeScript("arguments[0].scrollIntoView(true);", this);
this.logger().warn("Element can't be scrolled into view", ex);
}
}

Expand All @@ -115,8 +139,7 @@ public void waitForServerLoadToFinish()
final Boolean retVal = (Boolean)this.executeScript(this.waitForServerLoadToFinishFunction);
if(retVal == null)
{
LoggerFactory.getLogger(this.getClass())
.warn("waitForLoadToFinishFunction returned null! It should either return true or false");
this.logger().warn("waitForLoadToFinishFunction returned null! It should either return true or false");
}
finished = Boolean.TRUE.equals(retVal);
}
Expand Down