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

Karate UI - javascript error: Unexpected token #2665

Open
ravikiranbsl opened this issue Mar 10, 2025 · 5 comments
Open

Karate UI - javascript error: Unexpected token #2665

ravikiranbsl opened this issue Mar 10, 2025 · 5 comments

Comments

@ravikiranbsl
Copy link

Hi @ptrthomas Using Karate UI: Getting Below error While clicking or mouse-clicking on an element. When I try to locate the xpath in the application, it's pointing to the expected element. but when I try to execute, I'm getting the below error. Could you please suggest how to fix this type of exceptions?

And click("(//button[@aria-label='Continue'])[last()]")

or 

And mouse("(//button[@aria-label='Continue'])[last()]").click()

Error: com.intuit.karate - http response code: 500, response: {"value":{"error":"javascript error","message":"javascript error: Unexpected token '}'

@ptrthomas
Copy link
Member

at the very least kindly provide a way to replicate

anyway, I think using locators with parantheses and the use of last() has some subtle bugs. see if you can use pure css locators and the concept of "tree walking" in the meantime as a workaround: https://github.com/karatelabs/karate/tree/master/karate-core#tree-walking

to reopen, follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue

even better please try to contribute code or a PR, or influence your team / org to do so

@ravikiranbsl
Copy link
Author

ravikiranbsl commented Mar 10, 2025

This example may not be the exact replica, but we can use this as an example.

Here scenario: assumption is the last link name is dynamically changing.

Sample Website: http://the-internet.herokuapp.com/

```
# Click on last url
Given driver http://the-internet.herokuapp.com/
And click("(//li)[last()]")


Error:

> js failed:
>>>>
01: click("(//li)[last()]")
<<<<
org.graalvm.polyglot.PolyglotException: js eval failed twice:(//li)[last()].click(), error: [type: MAP, value: {type=object, subtype=error, className=SyntaxError, description=SyntaxError: Unexpected end of input, objectId=-4957699248285031102.1.3}]

Could be the reason I'm getting this javascript error: Unexpected token, since i'm using webdriver manager

In my application, only mouse clicks are working due to some application limitations

i tried below approach aswell


 Given driver http://the-internet.herokuapp.com/
    * def ele = locateAll("//button[@aria-label='Continue']")
    * def size = karate.sizeOf(ele)-1
    * print 'size :::: ', size
    * print ele[size]
    And mouse(ele[size]).click()


 Given driver http://the-internet.herokuapp.com/
    * def ele = locateAll("//button[@aria-label='Continue']")
    * def size = karate.sizeOf(ele)-1
    * print 'size :::: ', size
    * print ele[size]
    And click(ele[size])





Getting below exception: 

<img width="1720" alt="Image" src="https://github.com/user-attachments/assets/32f89641-fc9d-4f57-9001-c91ebd2369cf" />

@ptrthomas
Copy link
Member

reopening, but marked as help wanted contributions welcome

@ravikiranbsl
Copy link
Author

ravikiranbsl commented Mar 10, 2025

Could you please suggest where I should start/check to work on this issue?

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

No branches or pull requests

2 participants