This is a custom dropdown (looks like Bitrix24 CRM), not a native <select>. You need to simulate the click interaction
via JavaScript. Here's how:
Step 1: Click the dropdown to open it
// First, click the dropdown to open the options popup
oWebView:ExecuteScript( ;
'document.querySelector(''[data-name="UF_CRM_1768552906866"]'').click()' )
Step 2: Wait briefly, then click the desired option
The popup is dynamically created. After clicking, Bitrix renders a menu with main-ui-select-inner-item elements. You
need a small delay:
// Select "Option 3" (VALUE=1854) after a short delay
oWebView:ExecuteScript( ;
'setTimeout(function() {' + ;
' var items = document.querySelectorAll(".main-ui-select-inner-item");' + ;
' for (var i = 0; i < items.length; i++) {' + ;
' if (items[i].textContent.trim() === "Option 3") {' + ;
' items[i].click();' + ;
' break;' + ;
' }' + ;
' }' + ;
'}, 300)' )
Alternative: Select by VALUE instead of text
If you know the value (e.g. 1854), you can set it directly via the data attributes:
// Programmatically set the value by manipulating the data-value attribute
// and dispatching the change event
local cJS := ;
'var el = document.querySelector(''[data-name="UF_CRM_1768552906866"]'');' + ;
'var items = JSON.parse(el.getAttribute("data-items"));' + ;
'var target = items.find(function(i) { return i.VALUE == 1854; });' + ;
'if (target) {' + ;
' items.forEach(function(i) { i.IS_SELECTED = false; });' + ;
' target.IS_SELECTED = true;' + ;
' el.setAttribute("data-items", JSON.stringify(items));' + ;
' el.setAttribute("data-value", JSON.stringify(target));' + ;
' el.querySelector(".main-ui-select-name").textContent = target.NAME;' + ;
' el.click();' + ;
' setTimeout(function() {' + ;
' var popup = document.querySelectorAll(".main-ui-select-inner-item");' + ;
' for (var i = 0; i < popup.length; i++) {' + ;
' if (popup[i].textContent.trim() === target.NAME) {' + ;
' popup[i].click(); break;' + ;
' }' + ;
' }' + ;
' }, 300);' + ;
'}'
oWebView:ExecuteScript( cJS )
Complete helper function:
function SelectUIOption( oWebView, cFieldName, xValue )
local cJS
// xValue can be numeric (VALUE) or string (NAME)
if ValType( xValue ) == "N"
cJS := 'var el = document.querySelector(''[data-name="' + cFieldName + '"]'');' + ;
'el.click();' + ;
'setTimeout(function() {' + ;
' var items = JSON.parse(el.getAttribute("data-items"));' + ;
' var t = items.find(function(i){ return i.VALUE == ' + LTrim(Str(xValue)) + '; });' + ;
' if (t) {' + ;
' var popup = document.querySelectorAll(".main-ui-select-inner-item");' + ;
' for (var i = 0; i < popup.length; i++) {' + ;
' if (popup[i].textContent.trim() === t.NAME) { popup[i].click(); break; }' + ;
' }' + ;
' }' + ;
'}, 300)'
else
cJS := 'document.querySelector(''[data-name="' + cFieldName + '"]'').click();' + ;
'setTimeout(function() {' + ;
' var popup = document.querySelectorAll(".main-ui-select-inner-item");' + ;
' for (var i = 0; i < popup.length; i++) {' + ;
' if (popup[i].textContent.trim() === "' + xValue + '") { popup[i].click(); break; }' + ;
' }' + ;
'}, 300)'
endif
oWebView:ExecuteScript( cJS )
return nil
Usage:
// By value
SelectUIOption( oWebView, "UF_CRM_1768552906866", 1854 )
// By name
SelectUIOption( oWebView, "UF_CRM_1768552906866", "Option 3" )
The key insight is that these Bitrix custom dropdowns require two clicks: one to open the popup, then one on the
option. The setTimeout gives the popup time to render. If 300ms isn't enough, increase to 500.