python - 如何使用 selenium Web 驱动程序 python 在 html 中的标签之间添加标签
问题描述
我想在网站的文本编辑器/文本框中插入像粗体这样的格式化文本,我该怎么做?
我试过这个:
browser.find_element_by_xpath("/html/body/div[4]/div/div/div[2]/div/div")
browser.execute_script("arguments[0].AdjacentHTML('beforebegin', arguments[1])", node, <'strong> bold </'strong>)
但是,这似乎在文本框内添加了与 HTML 相邻的内容。
解决方案
我会使用 js 方法'setAttribute':
browser.execute_script("arguments[0].setAttribute('style', arguments[1]);",node, "font-weight: bold");
推荐阅读
- swagger - Swagger-net(或 swashbuckle):如何在 xml 请求中设置命名空间?
- javascript - ReactJS将选择发送回父级
- jquery - 停止“Div”改变位置“悬停”
- ios - 如何搜索表格数据
- c - c中的二进制加法,为什么会出现运行时错误?
- javascript - 如何替换或交换数组?
- c# - 如何从下拉列表中获取项目作为输出两次或三次或任意次数作为用户输入
- javascript - 在字符串中查找 `'('+any number+')'` 并拆分 JavaScript
- asp.net - 如何通过另一个请求停止长时间运行的请求
- python - 对无法正常使用双打的字典列表进行排序