Page 1 of 1

SelectBy.Script

Posted: Fri Nov 29, 2019 2:04 am
by cindyh
I think it's easiest to find my selections by Javascript and regex. But I don't see an example of what a SelectBy.Script should look like. Woud this be legitimate (I would eventually replace the innerText assignment with a regex replce).

Code: Select all

SelectBy.Script
   ·  "var s=createElement(\"p\");s.innerText='description'; return s;"
And the escaping of \\ seems to be weird when I've tried it (I need to look for the \ character in my regex, which escapes as \\ in my regex, and that becomes \\\\ in the SelectBy.Script string????

Cindy

Re: Select.ByScript

Posted: Fri Nov 29, 2019 4:26 pm
by doncorleone
It'd be easier if you add your script to Scripting > Scripts in project explorer and then did

Code: Select all

SelectBy.Script
   ·  Script.MyScript
That way you won't need to add any extra escape characters plus you'll get code completion. Your script should work and select the element you're creating but not sure why you'd want to create an element and then select it?

Re: Select.ByScript

Posted: Sun Dec 01, 2019 5:37 pm
by cindyh
Do I have to create an element, or can I just return a string from the page slected by regex? That was my goal - to put in the text of that element a regex selection from the content on the page. The documentation says your byscript has to return "an element", so I didnt know if that was a DOM element, or simply a string value would do.

Re: Select.ByScript

Posted: Mon Dec 02, 2019 5:22 pm
by webmaster
Yes, Select.ByScript must return a DOM element or a list of DOM elements. I guess the documentation should be explicit about this. If you just need to get a string from a script, you can use Browser.EvalScript like this:

Code: Select all

Browser.EvalScript
   ·  "return 'Hello World!';"
   ·  0
as myString
extract
   test
      myString
or just:

Code: Select all

extract
   test
      Browser.EvalScript
         ·  "return 'Hello World!';"
         ·  0