Execute Jquery with null condition using Selenium Python

156 Views Asked by At

Hi I tried to send javascript that look like this :

$("img[src|='']").attr('src', result.responseJSON.data);

It's to change image with null value to new value. I'm using execute script so that it looks like this :

driver.execute_script("$("img[src|='']").attr("src", result.responseJSON.data);}});")

and

driver.execute_script('$("img[src|='']").attr('src', result.responseJSON.data);}});')

but it always return an error like

enter image description here

or

enter image description here

I also signing it to a python variable and call it with execute script but no luck, any hint to fix it? Thanks in advance.

1

There are 1 best solutions below

0
On BEST ANSWER

Finally I found the answer, I should put escape char before like :

driver.execute_script("$(\"img[src|='']\").attr("src", result.responseJSON.data);")

and it works.