how to setValue in Pre Tag

149 views
Skip to first unread message

Sudhir Goswami

unread,
Apr 24, 2019, 7:42:36 AM4/24/19
to NightwatchJs
Hi All,

Below is the HTML Code.


<div class="CodeMirror-code">
<div style="position: relative;">
<div 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 ">
<span style="padding-right: 0.1px;">
<span cm-text="">&#8203;</span>
</span>
</pre>
</div>
</div>



Above code dislaying one textbox to enter the text.

Please help me how to write the code in nightwatch.

I am trying this way

Given(/^User enter the sql query in textbox$/, async ()
=> {
await client
.setValue("#CodeMirror-line" , "Select * from test")
.useXpath()
.useCss()
.pause(10000)
});
Need Help.png

Juan Koegelenberg

unread,
Apr 24, 2019, 7:55:15 AM4/24/19
to nightw...@googlegroups.com
Hi Sudhir

You need to first use the 'selector' and then the path to it, like:

.useCss();
.setValue("css path to element", "some text");
.pause(10000);

or use xpath

.UseXpath();
.setValue("xpath to element", "some text");
.pause(10000);

not both.

Regrads;
Juan



--
You received this message because you are subscribed to the Google Groups "NightwatchJs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.
To post to this group, send email to nightw...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nightwatchjs/904de9a3-5a49-447d-9e3d-b72bd2b594bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Kind regards
Juan Koegelenberg

Sudhir Goswami

unread,
Apr 24, 2019, 8:09:30 AM4/24/19
to NightwatchJs
Thanks for your reply!

I am getting below error.

Error while running .locateSingleElement() protocol action: no such element: Unable to locate element: {"method":"css selector","selector":"#CodeMirror-line"}


Thanks
Sudhir
To unsubscribe from this group and stop receiving emails from it, send an email to nightw...@googlegroups.com.

To post to this group, send email to nightw...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nightwatchjs/904de9a3-5a49-447d-9e3d-b72bd2b594bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Juan Koegelenberg

unread,
Apr 24, 2019, 9:34:27 AM4/24/19
to nightw...@googlegroups.com
Hi

If you are using css, the element should be 'pre.CodeMirror-line' as the class name. With # you are referencing the id not the class name.
So perhaps  'pre.CodeMirror-line' will work. Have a look at, http://learn-automation.com/write-dynamic-css-selector-in-selenium/, to find css selectors.

Regards;
Juan 

To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.

To post to this group, send email to nightw...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Sudhir Goswami

unread,
Apr 25, 2019, 5:23:43 AM4/25/19
to NightwatchJs
I tried a lot but its not working. 

<div style="position: relative;"><div 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 ">
<span style="padding-right: 0.1px;">
          <span cm-text="">&#8203;</span>      // Here when I enter the text from UI it increasing dynamically
</span>
</pre>
</div>


I have gone through the article which you provide. I found for class Only need to do eg .<className


Juan Koegelenberg

unread,
Apr 25, 2019, 5:29:26 AM4/25/19
to nightw...@googlegroups.com
Hi

Right click in the text box and select "inspect", then right click on element and select "copy" - "copy selector". Use this as css slector.

Hope that helps.
Juan

To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.

To post to this group, send email to nightw...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Sudhir Goswami

unread,
Apr 25, 2019, 5:51:06 AM4/25/19
to NightwatchJs
Hi Juan,


Given(/^User enter the sql query in textbox$/, async ()
=> {
await client
.useXpath()
.setValue('body > div.view-container > div > div > div.row > div > div:nth-child(1) > div:nth-child(1) > div > div:nth-child(2) > div > div.ng-scope > div > form > div:nth-child(2) > div > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre > span > span' , 'Select * from test')
.pause(3000)
});

Error
       Error while running "setValue" command: this.reporter.registerTestError is not a function
       TypeError: Error while running "setValue" command: this.reporter.registerTestError is not a function
           at transport.locateElement.then.then.catch.result 



    Sorry to asking you multiple times. May be I am doing some silly mistake.

Juan Koegelenberg

unread,
Apr 25, 2019, 6:43:26 AM4/25/19
to nightw...@googlegroups.com
Hi

You need to .useCss() since you are using the css selector.

Regards;
Juan

To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.

To post to this group, send email to nightw...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Per Täljemark

unread,
Apr 25, 2019, 6:57:10 AM4/25/19
to NightwatchJs
Hi,

The problem doesn't lie in you using Css or Xpath selector. A <pre> tag is not-editable so you won't be able to use setValue() on the element even if you manage to locate it.

A quick test I did on a dummy page having a <pre> item gave the following response.

browser
      .useXpath()
      .waitForElementPresent('//body', 'Loading page')
  .setVal('//pre','Override value')
    ;

√ Loading page
 Error while running .clearElementValue() protocol action: invalid element state: Element must be user-editable in order to clear it.

   An error occurred while running .clearValue() command on <//pre>: invalid element state: Element must be user-editable in order to clear it.
       at process._tickCallback (internal/process/next_tick.js:68:7)
 Error while running .setElementValue() protocol action: element not interactable

   An error occurred while running .setValue() command on <//pre>: element not interactable
       at process._tickCallback (internal/process/next_tick.js:68:7)

However, with CSS styling you should be able to create a text field to not look like a text field. If you really want to be able to change the text.



Sudhir Goswami

unread,
Apr 25, 2019, 8:08:01 AM4/25/19
to NightwatchJs
Hi,

But from UI Side I am able to insert the text. I noticed <Pre> <span> </span>.

body > div.view-container > div > div > div.row > div > div:nth-child(1) > div:nth-child(1) > div > div:nth-child(2) > div > div.ng-scope > div > form > div:nth-child(2) > div > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre > span > span



above is the complete copy selector.

Please correct me. Can't we setValue inside the span?

Please find attached screenshot.

@Juan: I tried .UseCss but that is also not working.

Thanks
Sudhir




--
Kind regards
Juan Koegelenberg

--
You received this message because you are subscribed to the Google Groups "NightwatchJs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nightw...@googlegroups.com.
To post to this group, send email to nightw...@googlegroups.com.
Need Help.png

David Linse

unread,
Apr 25, 2019, 9:37:09 AM4/25/19
to nightw...@googlegroups.com
u cannot set a value for a non-input element.. 

To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.

To post to this group, send email to nightw...@googlegroups.com.

Sudhir Goswami

unread,
Apr 29, 2019, 6:03:27 AM4/29/19
to NightwatchJs
Hi All,

I got an understanding of we can't set any value for non-input element.
But client not going to change their code. 

So Is there any way or workaround to achieve this.

Thanks
Sudhir

Sudhir Goswami

unread,
May 3, 2019, 5:38:15 AM5/3/19
to NightwatchJs
Please complete the thread I got the solution.
Reply all
Reply to author
Forward
0 new messages