python - 如何在python中更改selenium的属性?

标签 python selenium

我需要在 python 中使用 selenium 更改 img 标记中的 src 属性。

浏览器是 firefox

HTML代码:

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

需要更改为:

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

Python代码:

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

但是这段代码不起作用:-(

最佳答案

尝试实现以下行

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

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

关于python - 如何在python中更改selenium的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48622500/

相关文章:

javascript - 从基于网络的市场远程在 Android 上安装应用程序

Python + GStreamer - 无法连接

python - 使用 scipy.integrate.odeint 求解 odes 系统(不断变化!)?

python - 使用 BeautifulSoup 提取时保留某些 HTML 标签

java - 如何在 findElement(By.xpath ("//span[contains(text(),' string')]")) 中使用表达式

html - 如何在 Selenium 中找到元素

python - 将 Dataframe 转换为 Pandas 系列系列

python - PyTorch 中 "*"运算符在张量大小之前做什么?

java - Selenium GRID 测试执行

Python Selenium is_displayed() 返回 true 并且仍然引发 ElementNotVisible 异常?