How to get the contents of a script tag in Selenium

后端 未结 2 1600
日久生厌
日久生厌 2021-01-18 01:46

I\'m using Selenium with C#. I have code which returns me a script tag as an IWebElement. How do I get the content from it?

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-18 02:19

    You can try this:

    WebElement element = driver.findElement(By.tagName("script"));
    String htmlCode = (String) ((JavascriptExecutor) driver).executeScript("return arguments[0].innerHTML;", element);
    

    P.S. is in Java but you can do same in C# with some small edit.

提交回复
热议问题