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

[Bug]: When calling locator.locator -> 'Unsupported token "@class" while parsing selector...' #34147

Open
romsper opened this issue Dec 27, 2024 · 1 comment

Comments

@romsper
Copy link

romsper commented Dec 27, 2024

Version

1.49.0

Steps to reproduce

  1. Clone this repo: https://github.com/romsper/qa-automation-base/tree/kotlin-junit5-playwright
  2. Run this test: checkSpiderMan()

Expected behavior

I would like to find a nested element and map it to an object

Actual behavior


Error {
  message='Unsupported token "@class" while parsing selector ".div[@class='ml-4']/div[1]"
  name='Error
  stack='Error: Unsupported token "@class" while parsing selector ".div[@class='ml-4']/div[1]"
    at parseCSS (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/cssParser.js:64:31)
    at parseSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/selectorParser.js:50:49)
    at splitSelectorByFrame (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/selectorParser.js:99:20)
    at FrameSelectors.resolveFrameForSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frameSelectors.js:110:66)
    at FrameSelectors.resolveInjectedForSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frameSelectors.js:152:33)
    at /private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1482:47
    at Frame.retryWithProgressAndTimeouts (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:935:30)
    at /private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1481:28
    at ProgressController.run (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/progress.js:78:23)
    at Frame._callOnElementOnceMatches (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1479:23)
}
Call log:
-   - waiting for //*[@id='tbody']/tr >> nth=0 >> .div[@class='ml-4']/div[1]

com.microsoft.playwright.PlaywrightException: Error {
  message='Unsupported token "@class" while parsing selector ".div[@class='ml-4']/div[1]"
  name='Error
  stack='Error: Unsupported token "@class" while parsing selector ".div[@class='ml-4']/div[1]"
    at parseCSS (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/cssParser.js:64:31)
    at parseSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/selectorParser.js:50:49)
    at splitSelectorByFrame (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/selectorParser.js:99:20)
    at FrameSelectors.resolveFrameForSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frameSelectors.js:110:66)
    at FrameSelectors.resolveInjectedForSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frameSelectors.js:152:33)
    at /private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1482:47
    at Frame.retryWithProgressAndTimeouts (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:935:30)
    at /private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1481:28
    at ProgressController.run (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/progress.js:78:23)
    at Frame._callOnElementOnceMatches (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1479:23)
}
Call log:
-   - waiting for //*[@id='tbody']/tr >> nth=0 >> .div[@class='ml-4']/div[1]

	at com.microsoft.playwright.impl.WaitableResult.get(WaitableResult.java:56)
	at com.microsoft.playwright.impl.ChannelOwner.runUntil(ChannelOwner.java:132)
	at com.microsoft.playwright.impl.Connection.sendMessage(Connection.java:130)
	at com.microsoft.playwright.impl.ChannelOwner.sendMessage(ChannelOwner.java:118)
	at com.microsoft.playwright.impl.FrameImpl.innerTextImpl(FrameImpl.java:526)
	at com.microsoft.playwright.impl.FrameImpl.lambda$innerText$22(FrameImpl.java:517)
	at com.microsoft.playwright.impl.LoggingSupport.withLogging(LoggingSupport.java:47)
	at com.microsoft.playwright.impl.ChannelOwner.withLogging(ChannelOwner.java:97)
	at com.microsoft.playwright.impl.FrameImpl.innerText(FrameImpl.java:517)
	at com.microsoft.playwright.impl.LocatorImpl.innerText(LocatorImpl.java:375)
	at com.microsoft.playwright.Locator.innerText(Locator.java:3845)
	at pages.DynamicTablePage.getSuperheroes(DynamicTablePage.kt:18)
	at DynamicTableTest.checkSpiderMan(DynamicTableTest.kt:12)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
Caused by: com.microsoft.playwright.impl.DriverException: Error {
  message='Unsupported token "@class" while parsing selector ".div[@class='ml-4']/div[1]"
  name='Error
  stack='Error: Unsupported token "@class" while parsing selector ".div[@class='ml-4']/div[1]"
    at parseCSS (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/cssParser.js:64:31)
    at parseSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/selectorParser.js:50:49)
    at splitSelectorByFrame (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/selectorParser.js:99:20)
    at FrameSelectors.resolveFrameForSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frameSelectors.js:110:66)
    at FrameSelectors.resolveInjectedForSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frameSelectors.js:152:33)
    at /private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1482:47
    at Frame.retryWithProgressAndTimeouts (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:935:30)
    at /private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1481:28
    at ProgressController.run (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/progress.js:78:23)
    at Frame._callOnElementOnceMatches (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1479:23)
}
Call log:
-   - waiting for //*[@id='tbody']/tr >> nth=0 >> .div[@class='ml-4']/div[1]

	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:130)
	... 14 more


Error {
  message='Unsupported token "@class" while parsing selector ".div[@class='ml-4']/div[1]"
  name='Error
  stack='Error: Unsupported token "@class" while parsing selector ".div[@class='ml-4']/div[1]"
    at parseCSS (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/cssParser.js:64:31)
    at parseSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/selectorParser.js:50:49)
    at splitSelectorByFrame (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/selectorParser.js:99:20)
    at FrameSelectors.resolveFrameForSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frameSelectors.js:110:66)
    at FrameSelectors.resolveInjectedForSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frameSelectors.js:152:33)
    at /private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1482:47
    at Frame.retryWithProgressAndTimeouts (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:935:30)
    at /private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1481:28
    at ProgressController.run (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/progress.js:78:23)
    at Frame._callOnElementOnceMatches (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1479:23)
}
Call log:
-   - waiting for //*[@id='tbody']/tr >> nth=0 >> .div[@class='ml-4']/div[1]

com.microsoft.playwright.impl.DriverException: Error {
  message='Unsupported token "@class" while parsing selector ".div[@class='ml-4']/div[1]"
  name='Error
  stack='Error: Unsupported token "@class" while parsing selector ".div[@class='ml-4']/div[1]"
    at parseCSS (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/cssParser.js:64:31)
    at parseSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/selectorParser.js:50:49)
    at splitSelectorByFrame (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/utils/isomorphic/selectorParser.js:99:20)
    at FrameSelectors.resolveFrameForSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frameSelectors.js:110:66)
    at FrameSelectors.resolveInjectedForSelector (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frameSelectors.js:152:33)
    at /private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1482:47
    at Frame.retryWithProgressAndTimeouts (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:935:30)
    at /private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1481:28
    at ProgressController.run (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/progress.js:78:23)
    at Frame._callOnElementOnceMatches (/private/var/folders/fz/dqd2bcr91zj7y1m8p328cpmh0000gn/T/playwright-java-5802737314774923952/package/lib/server/frames.js:1479:23)
}
Call log:
-   - waiting for //*[@id='tbody']/tr >> nth=0 >> .div[@class='ml-4']/div[1]

	at app//com.microsoft.playwright.impl.Connection.dispatch(Connection.java:259)
	at app//com.microsoft.playwright.impl.Connection.processOneMessage(Connection.java:211)
	at app//com.microsoft.playwright.impl.ChannelOwner.runUntil(ChannelOwner.java:130)
	at app//com.microsoft.playwright.impl.Connection.sendMessage(Connection.java:130)
	at app//com.microsoft.playwright.impl.ChannelOwner.sendMessage(ChannelOwner.java:118)
	at app//com.microsoft.playwright.impl.FrameImpl.innerTextImpl(FrameImpl.java:526)
	at app//com.microsoft.playwright.impl.FrameImpl.lambda$innerText$22(FrameImpl.java:517)
	at app//com.microsoft.playwright.impl.LoggingSupport.withLogging(LoggingSupport.java:47)
	at app//com.microsoft.playwright.impl.ChannelOwner.withLogging(ChannelOwner.java:97)
	at app//com.microsoft.playwright.impl.FrameImpl.innerText(FrameImpl.java:517)
	at app//com.microsoft.playwright.impl.LocatorImpl.innerText(LocatorImpl.java:375)
	at app//com.microsoft.playwright.Locator.innerText(Locator.java:3845)
	at app//pages.DynamicTablePage.getSuperheroes(DynamicTablePage.kt:18)
	at app//DynamicTableTest.checkSpiderMan(DynamicTableTest.kt:12)
	at [email protected]/java.lang.reflect.Method.invoke(Method.java:566)
	at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1541)
	at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1541)

Additional context

How can I do that?
This approach is essential in automation testing especially if you work with marketplaces or something that reuses the same component.

Environment

Language: Java/Kotlin
Playwright version: 1.49.0
Browser: Chromium
@dgozman
Copy link
Contributor

dgozman commented Dec 27, 2024

@romsper The string .div[@class='ml-4']/div[1] is neither a valid xpath selector nor a valid css selector. What do you expect it to do?

Note that you should prefix non-obvious css selectors with css= and non-obvious xpaths with xpath=. For example:

locator.locator("xpath=.div[@class='ml-4']/div[1]")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants