【问题标题】:How to add tags between tags in html using selenium web driver python如何使用 selenium Web 驱动程序 python 在 html 中的标签之间添加标签
【发布时间】:2021-03-18 00:24:53
【问题描述】:

我想在网站的文本编辑器/文本框中插入像 粗体 这样的格式化文本,我该怎么做?

我试过这个:

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 的旁边而不是在文本框内添加的。

【问题讨论】:

    标签: python html python-3.x selenium


    【解决方案1】:

    我会使用 js 方法'setAttribute':

    browser.execute_script("arguments[0].setAttribute('style', arguments[1]);",node, "font-weight: bold");
    

    【讨论】:

    • 我有 html 我如何向其中添加 html html 包含
        等属性
    • 但是你的目的不是改变网页元素的风格吗?
    猜你喜欢
    • 2012-10-17
    • 2016-12-03
    • 2019-04-05
    • 1970-01-01
    • 2022-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多