Hi buddies!
I’m making a project that interacts with a webpage, in order to catch download links get and set values of Webpage controls like: Buttons, INPUT, Radiobuttons and Select HTML objects.
For get and set values of the radio buttons and Input controls I have no problem.
The problem is to set an option of a SELECT control. I only can get the selected value and get the selected index.
But I can’t set it.
That’s what I’m doing:
document.getElementById(‘DdlAnio’).selectedIndex //////////////Get the selected Index
document.getElementById(‘DdlAnio’).value//////////// Get the selected value.
I’m reading in W3Schools that doing this Works for set an option in Select, but doesn’t work for me, I tested in TryIt and jsFiddle with an example of select control and works.
But when I’m trying to set the values on the desired page, It doesn’t work:
document.getElementById(‘DdlAnio’).selectedIndex = ‘2’ //////////////Set the selected Index
document.getElementById(‘DdlAnio’).value = ‘2013’’ ////////Set the selected Value
W3Schools - selectedIndex Property
This to try to set ‘2013’ value.
And this is a part of source code, where appears that control:
2011
2012
2013
2014
2015
The web page is not mine, cuz of this I can’t edit the code, and I using an HTMLViewer to view the results and Execute Javascript to do the Js Code:
Dim JsElement As String= “setOption();” _
+“function setOption() {” _
+“document.getElementById(‘DdlAnio’).selectedIndex = ‘2’” _
+"}" _
HTMLViewer1.ExecuteJavaScript(JsElement)
But I can’t results, what Am I doing wrong?