2

I need change src attribute in img tag with selenium in python.

Browser is firefox.

HTML code:

<div style="" id="image_sec">
    <img src="city.png" alt="">
</div>

need change to:

<div style="" id="image_sec">
    <img src="new_city.png" alt="">
</div>

Python code:

driver.execute_script('$("#image_sec img").innerHtml(<img src="new_city.png" alt="">);')

But this code is not work :-(

1 Answer 1

3

Try to implement below line

driver.execute_script('document.querySelector("#image_sec>img").src="new_city.png";')

or

driver.execute_script('document.querySelector("#image_sec>img").setAttribute("src", "new_city.png");')
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.