Skip to content
Advertisement

How to write in pre tag?

I can’t write value to field using Selenium .sendKeys. So I use jsCode:

element = xpath(//pre[@role='presentation'])


executeJavaScript("arguments[0].value='RESPONSE';", element)

and

executeJavaScript("arguments[0].setAttribute('value', 'RESPONSE')", element);

I can’t understand why these methods don’t work – the test passes but the value is not written to the field

$("div pre").append("RESPONSE") – work in devTools

Full html code:

<body>
    <div style="position: relative;">
        <div aria-hidden="true" class="CodeMirror-gutter-wrapper" style="left: -30px;">
            <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">
                1
            </div>
        </div>
        <pre class="CodeMirror-line" role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span>​</span></span></pre>
    </div>
</body>

Advertisement

Answer

If you are trying to append to the content of the pre tag then use something like executeJavaScript("arguments[0].append('RESPONSE')", element);. That should append the response to the element in arguments[0].

If you are trying to set an attribute named value to the pre element. Then "arguments[0].setAttribute('value', 'RESPONSE')" sets <pre role='presentation' value="RESPONSE">.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement