How do I know a Locator really points to an existing element?

I am using #playwright-java , learning by doing, first time user.

I have been attracted by the ease of use seen in the demos.
However, when facing a complex website it turns out it needs more trial&&error than expected.

Now, when I put the xpath or full xpath I do not get my info :/
Tried (different) xpaths in full page, then in target frame, got them using my browser devtools.

Is there a way to know if a Locator is really points to an existing element ?
When I get an exception, the line numbers are (I believe) for typescript and do not help.

When using debugger, Locator object has xpath attribute set, else a frame reference.

I tried to use the recorder but the selector presented is based on the value.
For a value I get:

page.frameLocator(“#legacy-iframe-3755”).getByRole(AriaRole.CELL, new FrameLocator.GetByRoleOptions().setName(“xxxxx €”)).click();

This wont work in my context (#legacy-iframe-3755 is not a stable value).
Unless there is a way to get a solid (unmutable) xpath from a locator gotten from a value.

Here is the stacktrace, for documentation.

“The expression is not a legal expression” is rather poor.

The guilty code happens in the loop to address the different options of the select droplist.
It is :

Locator locatorTableauPositions = page.locator(Constantes.Positions.IDENTIFIANT_TABLEAU); 
// "xpath=//table@id=tabPTR"
int nombrePositions = locatorTableauPositions.locator("tr").count();    // BOOM

Is my locator not pointing to the target table ?

Is this not the way to get the rows count ?

com.microsoft.playwright.PlaywrightException: Error {
  message='Document.evaluate: The expression is not a legal expression
queryAll@debugger eval code:41:25
_queryEngineAll@debugger eval code:4949:49
querySelectorAll@debugger eval code:4936:30
@debugger eval code line 226 > eval:4:23
evaluate@debugger eval code:228:17
@debugger eval code:1:44

  name='Error
  stack='Error: Document.evaluate: The expression is not a legal expression
queryAll@debugger eval code:41:25
_queryEngineAll@debugger eval code:4949:49
querySelectorAll@debugger eval code:4936:30
@debugger eval code line 226 > eval:4:23
evaluate@debugger eval code:228:17
@debugger eval code:1:44

    at checkException (/tmp/playwright-java-5991555694620122335/package/lib/server/firefox/ffExecutionContext.js:111:121)
    at FFExecutionContext.evaluateWithArguments (/tmp/playwright-java-5991555694620122335/package/lib/server/firefox/ffExecutionContext.js:82:5)
    at async LongStandingScope._race (/tmp/playwright-java-5991555694620122335/package/lib/utils/manualPromise.js:96:14)
    at async evaluateExpression (/tmp/playwright-java-5991555694620122335/package/lib/server/javascript.js:241:12)
    at async FrameSelectors.queryCount (/tmp/playwright-java-5991555694620122335/package/lib/server/frameSelectors.js:74:12)
    at async Frame.queryCount (/tmp/playwright-java-5991555694620122335/package/lib/server/frames.js:736:12)
    at async FrameDispatcher.queryCount (/tmp/playwright-java-5991555694620122335/package/lib/server/dispatchers/frameDispatcher.js:135:14)
    at async LongStandingScope._race (/tmp/playwright-java-5991555694620122335/package/lib/utils/manualPromise.js:96:14)
    at async FrameDispatcher._handleCommand (/tmp/playwright-java-5991555694620122335/package/lib/server/dispatchers/dispatcher.js:96:14)
    at async DispatcherConnection.dispatch (/tmp/playwright-java-5991555694620122335/package/lib/server/dispatchers/dispatcher.js:361:22)
}
    at com.microsoft.playwright.impl.WaitableResult.get(WaitableResult.java:56)
    at com.microsoft.playwright.impl.ChannelOwner.runUntil(ChannelOwner.java:120)
    at com.microsoft.playwright.impl.Connection.sendMessage(Connection.java:130)
    at com.microsoft.playwright.impl.ChannelOwner.sendMessage(ChannelOwner.java:106)
    at com.microsoft.playwright.impl.FrameImpl.queryCount(FrameImpl.java:1116)
    at com.microsoft.playwright.impl.LocatorImpl.count(LocatorImpl.java:165)
    at org.wadael.bourdirconnect.PortefeuilleExtracteur.extraitPortefeuille(PortefeuilleExtracteur.java:153)
    at org.wadael.bourdirconnect.PortefeuilleExtracteur.extraitPortefeuille(PortefeuilleExtracteur.java:35)
    at LeTest.estCeQuilYADuContenu(LeTest.java:33)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:765)
    at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
    at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
    at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
    at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
    at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
    at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:218)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:214)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:139)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:198)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:169)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:93)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:58)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:141)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:57)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:103)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:85)
    at org.junit.platform.launcher.core.DelegatingLauncher.execute(DelegatingLauncher.java:47)
    at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:63)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: com.microsoft.playwright.impl.DriverException: Error {
  message='Document.evaluate: The expression is not a legal expression
queryAll@debugger eval code:41:25
_queryEngineAll@debugger eval code:4949:49
querySelectorAll@debugger eval code:4936:30
@debugger eval code line 226 > eval:4:23
evaluate@debugger eval code:228:17
@debugger eval code:1:44

  name='Error
  stack='Error: Document.evaluate: The expression is not a legal expression
queryAll@debugger eval code:41:25
_queryEngineAll@debugger eval code:4949:49
querySelectorAll@debugger eval code:4936:30
@debugger eval code line 226 > eval:4:23
evaluate@debugger eval code:228:17
@debugger eval code:1:44

    at checkException (/tmp/playwright-java-5991555694620122335/package/lib/server/firefox/ffExecutionContext.js:111:121)
    at FFExecutionContext.evaluateWithArguments (/tmp/playwright-java-5991555694620122335/package/lib/server/firefox/ffExecutionContext.js:82:5)
    at async LongStandingScope._race (/tmp/playwright-java-5991555694620122335/package/lib/utils/manualPromise.js:96:14)
    at async evaluateExpression (/tmp/playwright-java-5991555694620122335/package/lib/server/javascript.js:241:12)
    at async FrameSelectors.queryCount (/tmp/playwright-java-5991555694620122335/package/lib/server/frameSelectors.js:74:12)
    at async Frame.queryCount (/tmp/playwright-java-5991555694620122335/package/lib/server/frames.js:736:12)
    at async FrameDispatcher.queryCount (/tmp/playwright-java-5991555694620122335/package/lib/server/dispatchers/frameDispatcher.js:135:14)
    at async LongStandingScope._race (/tmp/playwright-java-5991555694620122335/package/lib/utils/manualPromise.js:96:14)
    at async FrameDispatcher._handleCommand (/tmp/playwright-java-5991555694620122335/package/lib/server/dispatchers/dispatcher.js:96:14)
    at async DispatcherConnection.dispatch (/tmp/playwright-java-5991555694620122335/package/lib/server/dispatchers/dispatcher.js:361:22)
}
    at com.microsoft.playwright.impl.Connection.dispatch(Connection.java:259)
    at com.microsoft.playwright.impl.Connection.processOneMessage(Connection.java:211)
    at com.microsoft.playwright.impl.ChannelOwner.runUntil(ChannelOwner.java:118)
    ... 75 more
 

org.opentest4j.AssertionFailedError: expected: not equal but was: <0>

    at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:152)
    at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
    at org.junit.jupiter.api.AssertNotEquals.failEqual(AssertNotEquals.java:277)
    at org.junit.jupiter.api.AssertNotEquals.assertNotEquals(AssertNotEquals.java:94)
    at org.junit.jupiter.api.AssertNotEquals.assertNotEquals(AssertNotEquals.java:86)
    at org.junit.jupiter.api.Assertions.assertNotEquals(Assertions.java:1981)
    at LeTest.estCeQuilYADuContenu(LeTest.java:41)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)


Process finished with exit code 255

Context:
I am trying to get my info from my broker account.
The code will be made public later although it will only be useful to the broker customers, mostly :fra: customers I believe. So I also pleased myself not coding in English this time.

Page has many frames and the info I am looking for is gotten from a sub page (php).
The iframe name changes over time so locator obtained from recorder is not possible for all infos
I looped in the frames, looked for the html declaring the select, then rewrote the different xpath for:

  • adapting to the frame html root (I loaded it in my browser and used devtools)
  • adapting to the row number

I tried accessing via xpath either from page or a shorter one from the frame.

Thank you for your time and expertise

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật