How to read text from hidden element with Selenium WebDriver?

后端 未结 8 2141
难免孤独
难免孤独 2020-11-27 15:38

I\'m trying to read the example String 1000 out of a hidden

like this:

相关标签:
8条回答
  • 2020-11-27 16:03

    EDIT: Oh this works.

    String script = "return document.getElementById('hidden_div').innerHTML";
    

    In firefox.

    And so does this.

    String script = "return arguments[0].innerHTML";
    

    I tried as well but it does not seem to work with pure Javascript. Start the browser with Jquery as mentioned here. How to use JQuery in Selenium? and use following code for script.

    String script = "return $('#hidden_div').text();";
    

    This works.

    0 讨论(0)
  • 2020-11-27 16:06

    I recommand to use:

    JavascriptExecutor js = (JavascriptExecutor)hiddenDiv;
    String n=(String) js.executeScript("return document.getElementById('hidden_div').value;");
    System.out.println(n);
    
    0 讨论(0)
提交回复
热议问题