I am accessing to my own robots via wi-fi using a third party router.
I wrote a small application that automatically log-in to the router, navigate through the tab
of the router interface all using JavaScript
inside a QML
application.
The small problem I have is that I have to trigger a relays to turn on/off the robot and inside the router GUI I need to trigger a combobox
as shown in the print screen below. After clicking on the I/O
tab, the address of the router page is https://123.456.789.123:7878/admin/ACEmanagerX.html#
:
The corresponding html
is also shown below:
EDITS
Now in order to replicate the problem I have I deployed a very small website https://comboboxtest.netlify.com/ that carries only one combobox with the same name and same choice I am trying to trigger.
The problem is that I can't find an easy ways to trigger the relays either on or off.
The expected behavior would be: if it is OFF
(value 0) put it ON
(value 1 which is Drive Active Low) and vice versa.
If you copy/paste the code below and run it it will automatically open the website but, unfortunately, it does not change the combobox from the OFF
position to Drive Active Low
and vice versa.
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtWebEngine 1.9
ApplicationWindow{
id: root
width: 1940
height: 1100
visible: true
property string cBox: "https://comboboxtest.netlify.com"
QtObject {
// Below property triggers the combo box of the relays evaluating the normally closed (NC) or
// normally opened (NO) circuit
property string get_normallyClosed_or_normallyOpened_comboBox: "
var comboBox = document.getElementsByName('859-2-2')[0];
comboBox.addEventListener('change', function (e) {
comboBox.options[0].selected = true;
if ('createEvent' in document) {
var evt = document.createEvent('HTMLEvents');
evt.initEvent('change', false, true);
sel.dispatchEvent(evt);
}
else {
sel.fireEvent('onchange');
}
});
sel.addEventListener('change', function (e) {
alert('changed');
});
".arg(cBox)
}
Timer {
id: timer
interval: 1000; repeat: false
onTriggered: view.runJavaScript(internals.get_normallyClosed_or_normallyOpened_comboBox)
}
WebEngineView {
id: view
anchors.fill: parent
onUrlChanged: {
console.log(url)
if(url === Qt.resolvedUrl("https://comboboxtest.netlify.com/"))
timer.running = true
}
onCertificateError: function(error) {
error.ignoreCertificateError();
}
Component.onCompleted: view.url = "https://comboboxtest.netlify.com"
}
}
What I tried so far
1) After going through this post I found out that it is very important to give time to the http
request to start. That is why I added interval: 20000
after entering in the I/O tab. However, that was not useful and the combobox wasn't triggered.
2) I used this source to help me figure out how to trigger the combobox via JavaScript
and that is exactly what I applied but I didn't see any value changed in the combobox.
3) I found this post which is very close to what I am doing, with the difference that here it was also used a Button
to trigger the combobox. But in my case I have no button.
I know I am close to have it working but there is something I am missing. Thank you for shedding light on this matter for solving the problem