'How to send Data to Xpath in Flutter
I have an app which listens serial port. When data has came, i need to set textbox value in web view. Text box has no id, no name, i need to set value with xpath. But when data came from serial port, i can't set the textbox value. I am not sure, what is the problem.
_serialData = "";
if (_subscription != null) {
_subscription!.cancel();
_subscription = null;
}
if (_transaction != null) {
_transaction!.dispose();
_transaction = null;
}
if (_port != null) {
_port!.close();
_port = null;
}
if (device == null) {
_device = null;
setState(() {
_status = "Bağlantı Koptu!";
});
return true;
}
_port = await device.create();
if (await (_port!.open()) != true) {
setState(() {
_status = "Bağlantı Noktası Açılamadı";
});
return false;
}
_device = device;
await _port!.setDTR(true);
await _port!.setRTS(true);
await _port!.setPortParameters(
1000000, UsbPort.DATABITS_8, UsbPort.STOPBITS_1, UsbPort.PARITY_NONE);
_transaction = Transaction.stringTerminated(
_port!.inputStream as Stream<Uint8List>, Uint8List.fromList([13, 10]));
_subscription = _transaction!.stream.listen((String line) {
setState(() {
if (_serialData != line) {
_serialData = line;
webViewController!
.runJavascript(
"var aranan = document.evaluate('/html/body/div/div/div[2]/div/div[2]/div[2]/div/div/form/div/input',document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
aranan.value='$line';"
);
}
});
});
Problem is _transaction!.stream.listen((String line) function. I can get data from serial port. There is no problem there. But i can't set this xpath "/html/body/div/div/div[2]/div/div[2]/div[2]/div/div/form/div/input"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
