【问题标题】:How to reomve particular tag and its value firm html content in selenium using java如何使用java从selenium中的html内容中删除特定标签及其值
【发布时间】:2021-02-15 21:04:29
【问题描述】:

我想为此从正文内容(html 页面)中删除一个 h1 标记值 我正在使用 String h1 = driver.findElement(By.xpath("//div[@class='tab_content active']/h1")).getText();字符串内容 = cont.replace(h1,"");
但通过这种方式,它会从内容和特定的 h1 标签中删除所有匹配的文本 任何人都可以建议如何做到这一点

【问题讨论】:

    标签: java html selenium testng


    【解决方案1】:
    String h1 = driver.findElement(By.xpath("//div[@class='tab_content active']/h1")).getText(); 
    
    String content = cont.replace("<h1>"+h1+"</h1>","<h1></h1>");
    

    它将删除特定的 h1 标记文本

    【讨论】:

    • 感谢您的回复,但它不会删除 h1 标签值
    • 您只需将其从值替换为仅保留空值
    猜你喜欢
    • 2020-11-11
    • 2017-07-23
    • 2022-11-21
    • 2023-03-12
    • 2014-08-19
    • 2010-12-03
    • 2012-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多