0

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.

7
  • Two thoughts: 1/ Does it work from devtools command line? - execute_script == command line (just operated a bit differently), if you can run on there you can get it to work in the other 2/ what is img? is that an object you want to pass in? Commented Sep 2, 2020 at 18:14
  • Img is a html tag, so i want to insert value to <img src=""> Commented Sep 2, 2020 at 18:31
  • Your null tag selection is correct but the way you call the execute script is completely off. Commented Sep 2, 2020 at 23:39
  • And how the correct way? Commented Sep 3, 2020 at 2:15
  • Do you need to define which image tag in particular? And did you try it in the console first? Commented Sep 3, 2020 at 6:05

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.