I am trying to automate a webpage using UiPath. It has two dropdowns as below
Upon selecting the Team, the Closure Category gets activated as below
While doing it with UiPath, I have used try-catch block with selectors in try block and incase it fails, in catch block I am using JScript to achieve the task.
The Html code for this two dropdowns are as below:
<select name="team" id="team" onchange="teamSelected();">
<option value="-1" selected="">Select Team...</option>
<option value="0">Game Security</option>
<option value="1">Security</option>
<option value="2" selected="true">Support</option>
<option value="3">Responsible Gaming</option>
<option value="4">Poker Room</option>
</select>
and the next one is
<select name="category" id="category" onchange="checkPermanentClosure();">
<option value="-1">Select Closure Category...</option>
<option value="9">Account Closure Request</option>
<option value="10">Abuse - Offensive Language or Content</option>
<option value="14">Approved User ID Change Request</option>
<option value="16">Client Hacking</option>
<option value="2">Colluder</option>
</select>
For injecting JScript I have written the below function
function SelectTeamForAccountClosure()
{
try{
for ( let i = 0; i < document.getElementById('team').children.length; i++)
{
if ( document.getElementById('team').children[i].innerText == 'Support')
{
document.getElementById('team').selectedIndex = i;
document.getElementById('team').onchange();
break;
}
}
}catch(e){
}
}
This function works perfectly when run inside the HTML Dom in Chrome, but UiPath fails to trigger
document.getElementById('team').onchange();
I have also tried using
document.getElementById('team').fireEvent("onchange");
but it seems like UiPath can not inject such java script and throwing error
TypeError: document.getElementById(...).onchange is not a function
It is same for fireEvent as well. Upon changing ContinueOnError to true, the error is not thrown but the work is also not done. It look like UiPath can only change the selected index of the dropdown but can not call the onchange function.
Is there any way to achieve this using inject JS activity in UiPath?