Unexpected token ‘<'

Tags: , , , ,



I am using this to add html between a div tag but it displays Unexpected token '<'

browser.execute_script("arguments[0].innerHTML = " + f'{x["solution"]}', solution)

The x["solution"] is a json file which contains html like <strong> bold </strong> etc.

Answer

You forgot to quote the right part of the equality. This code is generating:

arguments[0].innerHTML = <strong> bold </strong>

Also, you can use a single formatted string which would look like:

browser.execute_script(f'arguments[0].innerHTML = "{x["solution"]}"', solution)

and would generate

arguments[0].innerHTML = "<strong> bold </strong>"


Source: stackoverflow