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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.1.0
* Internal restructuring - new interfaces to deduplicate code
* Added `SimpleImprovedWebElement` which can be for direct instantiation

# 1.0.8
* Fix `ImprovedRemoteWebElement` not using correct search context

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

<groupId>software.xdev</groupId>
<artifactId>selenium-elements-root</artifactId>
<version>1.0.9-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<organization>
Expand Down
2 changes: 1 addition & 1 deletion selenium-elements/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>software.xdev</groupId>
<artifactId>selenium-elements</artifactId>
<version>1.0.9-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>selenium-elements</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,32 @@ default <T extends WebElement> T waitForFirst(
final Duration duration)
{
return this.elementProxyCreator().find(
by -> this.waitUntil(
wd -> this.determineSearchContext(wd)
.findElement(additionalAndBy != null ? new ByAnd(by, additionalAndBy) : by),
duration),
by -> {
final By byToUse;

final boolean byPresent = by != null;
final boolean additionalByPresent = additionalAndBy != null;
if(byPresent && additionalByPresent)
{
byToUse = new ByAnd(by, additionalAndBy);
}
else if(byPresent)
{
byToUse = by;
}
else if(additionalByPresent)
{
byToUse = additionalAndBy;
}
else
{
throw new IllegalStateException("No locator that is not null present");
}

return this.waitUntil(
wd -> this.determineSearchContext(wd).findElement(byToUse),
duration);
},
clazz);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright © 2025 XDEV Software (https://xdev.software)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package software.xdev.selenium.elements;

import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriver;


public interface CanFindElementsSelfSearchContext extends SearchContext, CanFindElements
{
@Override
default SearchContext determineSearchContext(final WebDriver webDriver)
{
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WrapsElement;
Expand All @@ -37,7 +36,7 @@
*
* @apiNote Requires a underlying {@link ImprovedRemoteWebElement}
*/
public interface ImprovedWebElement extends WebElement, CanFindElements, WrapsElement
public interface ImprovedWebElement extends WebElement, CanFindElementsSelfSearchContext, WrapsElement
{
default void performJsClick()
{
Expand All @@ -49,12 +48,6 @@ default void nativeClick()
this.getWrappedRemoteElement().nativeClick();
}

@Override
default SearchContext determineSearchContext(final WebDriver webDriver)
{
return this;
}

@Override
default WebDriver getWebDriver()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright © 2025 XDEV Software (https://xdev.software)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package software.xdev.selenium.elements;

/**
* This is a simple implementation of {@link ImprovedWebElement} because the later can't be directly instantiated.
* <p>
* Please note that it has no selectors and an additional selector is required for it to work properly.
* </p>
*/
public abstract class SimpleImprovedWebElement implements ImprovedWebElement
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
package software.xdev.selenium.elements.remote;

import org.openqa.selenium.ElementNotInteractableException;
import org.openqa.selenium.SearchContext;
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;
import software.xdev.selenium.elements.CanFindElementsSelfSearchContext;


/**
Expand All @@ -34,7 +33,7 @@
* </ul>
*/
@SuppressWarnings("java:S2160")
public class ImprovedRemoteWebElement extends RemoteWebElement implements CanFindElements
public class ImprovedRemoteWebElement extends RemoteWebElement implements CanFindElementsSelfSearchContext
{
protected Logger logger;
protected final String waitForServerLoadToFinishFunction;
Expand Down Expand Up @@ -66,12 +65,6 @@ public WebDriver getWebDriver()
return this.getWrappedDriver();
}

@Override
public SearchContext determineSearchContext(final WebDriver webDriver)
{
return this;
}

@Override
public void click()
{
Expand Down