put a string with html/Javascript into selenium webdriver

前端 未结 5 1200
不思量自难忘°
不思量自难忘° 2020-12-03 01:19

I have a html document in memory as a string. It contains a

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 01:54

    Just a small update: escapeEcmaScrip() replaces escapeJavaScript() in 2015.

    public static void main(String[] args) throws InterruptedException{ 
        driver = new FirefoxDriver();
        driver.get("http://dhtmlx.com/docs/products/dhtmlxTree/");
        replaceHTML(By.xpath("//*/span[text()='Supported browsers:']"), "");
    }
    
     private static void replaceHTML(By by, String html) {
          WebElement e = driver.findElement(by);
         ((JavascriptExecutor) driver).executeScript("arguments[0].innerHTML='" + StringEscapeUtils.escapeEcmaScript(html) + "'", e);
    
    }
    

提交回复
热议问题