Select dropmenu via executescript

@Plankton @ulrich @thecoder2012 @admin

I readed in katalon recorder forum that some select can choiced with script

It’s possibile to use similar script in ui vision ?

This is the script for katalon recorder to select drop menu

Command: runScript
Target: ;(function(){ (‘select[name=“chargingPoint.chargingPointType”]’).val(‘111’).trigger(‘change’); })(jQuery);

Here the link:

RunScript is almost exactly the same as executeScript :slight_smile:

The only difference is that “Run Script” does not store a script result value in a variable like executeScript does. But of course that is not important. => You can simply use executeScript instead.

I tried with executeScript but give an error how i can fix this ?

  • [error]
    Error in executeScript_Sandbox code: illegal character

{
“Command”: “executeScript_Sandbox”,
“Target”: “(function(){ (‘select[name=“chargingPoint.chargingPointType”]’).val(‘111’).trigger(‘change’); })(jQuery);”,
“Value”: “”
}

Here I show you some code that I’ve used to select from a dropdown, running it from executeScript:

function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
function setSelectedValue(selectObj, valueToSet) {
for (var i = 0; i < selectObj.options.length; i++) {
if (selectObj.options[i].text== valueToSet) {
selectObj.options[i].selected = true;
return;
}
}
}
var b = getElementByXpath("/html/body/form/div[11]/table/tbody/tr/td/table/tbody/tr[3]/td[2]/select");//example of path
setSelectedValue(b,"H"); // select option H
b.onchange();

Hope it helps you :wink:

It’s showed an error can you fix it please ?

  • [error]

[Line 1] Error in executeScript code: selectObj is null

that is that maybe it is not finding the path you gave it
did you change the xpath from the line var b = getElementByXpath("HERE ENTER THE XPATH OF THE DROP MENU"); ?

Can you post a url page and macro code to see how it works please ?

i don’t find any public page that has select dropdown and change action, Could you send me some page and i do the macro there? thanks