python-3.x - 如何在使用 selenium(python3)打开的网站中修改 html 代码?
问题描述
我有一个 python 脚本,可以打开一个带有 selenium 的网站。打开后,我希望 selenium 更改网站中某些按钮的 html 中的某些行。
这是我使用 chrome 开发工具检查页面时的实际代码
<button type="button" class="achieve-btn">Sometext & Sometext</button>
这就是我想用它修改代码
<button type="button" class="getExamButtonId1" onclick="openInstructionsPage(6012,'getExamButtonId1','incompleteExamId10001861')">Sometext & Sometext</button>
有可能吗?
如果可能,请提供要在我的脚本中编写的确切代码行以执行以下操作。
解决方案
您需要尝试修改innerHTML
此元素的属性。
element = driver.find_element_by_css_selector("button.achieve-btn")
driver.execute_script("arguments[0].innerHTML = 'your_html_code_here'", element)
推荐阅读
- node.js - Google Videointelligence API - UnhandledPromiseRejectionWarning,每分钟请求数
- javascript - ReatctJS ComponentDidUpdate 没有触发?
- java - 春豆不捡?
- python - 我想用空格字符在 Django 中保存 textarea
- c - read() 读取文件中不存在的字符
- scala - 折叠函数scala的不可变列表
- linux - linux:使用单个命令从两个目录中查找公共文件
- python - 当我尝试根据另一个嵌套列表对嵌套列表进行排序时,如何解决此错误?
- java - 扩展主机意外终止(vscode)
- python - Pandas 除法返回所有 NaN 的数据帧