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);
}
diff --git a/selenium-elements/src/main/java/software/xdev/selenium/elements/CanFindElementsSelfSearchContext.java b/selenium-elements/src/main/java/software/xdev/selenium/elements/CanFindElementsSelfSearchContext.java
new file mode 100644
index 0000000..2e788ad
--- /dev/null
+++ b/selenium-elements/src/main/java/software/xdev/selenium/elements/CanFindElementsSelfSearchContext.java
@@ -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;
+ }
+}
diff --git a/selenium-elements/src/main/java/software/xdev/selenium/elements/ImprovedWebElement.java b/selenium-elements/src/main/java/software/xdev/selenium/elements/ImprovedWebElement.java
index 3516af3..85d9ee5 100644
--- a/selenium-elements/src/main/java/software/xdev/selenium/elements/ImprovedWebElement.java
+++ b/selenium-elements/src/main/java/software/xdev/selenium/elements/ImprovedWebElement.java
@@ -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;
@@ -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()
{
@@ -49,12 +48,6 @@ default void nativeClick()
this.getWrappedRemoteElement().nativeClick();
}
- @Override
- default SearchContext determineSearchContext(final WebDriver webDriver)
- {
- return this;
- }
-
@Override
default WebDriver getWebDriver()
{
diff --git a/selenium-elements/src/main/java/software/xdev/selenium/elements/SimpleImprovedWebElement.java b/selenium-elements/src/main/java/software/xdev/selenium/elements/SimpleImprovedWebElement.java
new file mode 100644
index 0000000..8688e05
--- /dev/null
+++ b/selenium-elements/src/main/java/software/xdev/selenium/elements/SimpleImprovedWebElement.java
@@ -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.
+ *
+ * Please note that it has no selectors and an additional selector is required for it to work properly.
+ *
+ */
+public abstract class SimpleImprovedWebElement implements ImprovedWebElement
+{
+}
diff --git a/selenium-elements/src/main/java/software/xdev/selenium/elements/remote/ImprovedRemoteWebElement.java b/selenium-elements/src/main/java/software/xdev/selenium/elements/remote/ImprovedRemoteWebElement.java
index ba4a9ac..db088c3 100644
--- a/selenium-elements/src/main/java/software/xdev/selenium/elements/remote/ImprovedRemoteWebElement.java
+++ b/selenium-elements/src/main/java/software/xdev/selenium/elements/remote/ImprovedRemoteWebElement.java
@@ -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;
/**
@@ -34,7 +33,7 @@
*
*/
@SuppressWarnings("java:S2160")
-public class ImprovedRemoteWebElement extends RemoteWebElement implements CanFindElements
+public class ImprovedRemoteWebElement extends RemoteWebElement implements CanFindElementsSelfSearchContext
{
protected Logger logger;
protected final String waitForServerLoadToFinishFunction;
@@ -66,12 +65,6 @@ public WebDriver getWebDriver()
return this.getWrappedDriver();
}
- @Override
- public SearchContext determineSearchContext(final WebDriver webDriver)
- {
- return this;
- }
-
@Override
public void click()
{