Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebElementFacadeImpl::then* methods don't implement Lazy Loading Design Pattern fully #3344

Closed
emaks opened this issue Dec 3, 2023 · 5 comments
Labels
can't-fix We don't know how to do this at the moment

Comments

@emaks
Copy link
Contributor

emaks commented Dec 3, 2023

What happened?

No response

What did you expect to happen?

No response

Serenity BDD version

latest

JDK version

11

Execution environment

No response

How to reproduce the bug.

I try to use code like:

WebElementFacade parent = element("//parent-locator");
WebElementFacade child = parent.then(".//child-locator");
// some actions after which 'parent' and 'child' will be visible on page
parent.waitUntilVisible();
child.waitUntilVisible();

test fails on second line

Step failed
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//parent-locator"}
  (Session info: chrome=119.0.6045.161)
For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
Build info: version: '4.15.0', revision: '1d14b5521b'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.21'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [aa4fe1f879a8fec95dc02541729f222e, findElement {using=xpath, value=//parent-locator}]
Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 119.0.6045.161, chrome: {chromedriverVersion: 119.0.6045.105 (38c72552c5e..., userDataDir: C:\Users\yevma\AppData\Loca...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:61250}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: windows, proxy: Proxy(), se:cdp: ws://localhost:61250/devtoo..., se:cdpVersion: 119.0.6045.161, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
Session ID: aa4fe1f879a8fec95dc02541729f222e
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
	at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
	at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:52)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:191)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:200)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:175)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:607)
	at org.openqa.selenium.remote.ElementLocation$ElementFinder$2.findElement(ElementLocation.java:165)
	at org.openqa.selenium.remote.ElementLocation.findElement(ElementLocation.java:59)
	at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:364)
	at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:358)
	at net.thucydides.core.webdriver.WebDriverFacade.findElement(WebDriverFacade.java:259)
	at net.serenitybdd.core.pages.WebElementResolverByLocator.resolveForDriver(WebElementResolverByLocator.java:25)
	at net.serenitybdd.core.pages.WebElementFacadeImpl.getResolvedElement(WebElementFacadeImpl.java:188)
	at net.serenitybdd.core.pages.WebElementFacadeImpl.getElement(WebElementFacadeImpl.java:183)
	at net.serenitybdd.core.pages.WebElementFacadeImpl.findBy(WebElementFacadeImpl.java:231)
	at net.serenitybdd.core.pages.WebElementFacadeImpl.then(WebElementFacadeImpl.java:221)

@wakaleo
Copy link
Member

wakaleo commented Dec 3, 2023

When you use parent.waitUntilVisible(), Selenium will try to resolve the parent element before calling waitUntilVisible(), so it may timeout before it gets to the waitUntilVisibile() method. You can avoid this issue by using the withTimeoutOf() method.

@emaks
Copy link
Contributor Author

emaks commented Dec 3, 2023

test fails on WebElementFacade child = parent.then(".//child-locator"); line

@wakaleo
Copy link
Member

wakaleo commented Dec 3, 2023

no such element: Unable to locate element: {"method":"xpath","selector":"//parent-locator"} means Selenium can't find the element. You might need to wait until it is present.

@emaks
Copy link
Contributor Author

emaks commented Dec 3, 2023

yep, but I expect that http requests to get elements should be sent when I execute *.waitUntilVisible(). first two lines just elements initialization like we do using @findby annotation

@wakaleo
Copy link
Member

wakaleo commented Dec 3, 2023

That's not how Java or Selenium works.

@wakaleo wakaleo added the can't-fix We don't know how to do this at the moment label Dec 5, 2023
@wakaleo wakaleo closed this as completed Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't-fix We don't know how to do this at the moment
Projects
None yet
Development

No branches or pull requests

2 participants