Qt5-QML:在第三方设备上使用的自动身份验证用户名和密码

问题描述 投票:0回答:1

[了解了如何将JavaScript函数集成到Qt-QML中之后,我现在尝试将在my previous post中学到的知识应用到实验室中的一个小真实示例中。

我正在尝试使用实验室中存在的第三方设备通过wi-fi访问机器人。

我具有设备提供的登录表格,如下图所示。该地址例如是https://123.456.789.123:7878(我编写了该地址,但这是为了理解这个主意):

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLmltZ3VyLmNvbS9QRUNxSzdHLnBuZyJ9” alt =“登录”>

使用html浏览inspector tool页面后,我到达了log in按钮类,如下所示:

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLmltZ3VyLmNvbS9LajVwUVk2LnBuZyJ9” alt =“ inspector-tool”>

问题我有一个问题,我现在正在尝试自动填充log-in的密码并自动访问它。登录后,我应该可以看到下面的页面,但是没有。

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLmltZ3VyLmNvbS9vdFltMzRMLnBuZyJ9” alt =“登录后” >>>

我应该提到我重用了Quick Nanao Browser Example,因为当需要绕过需要认证的窗口时,它可以很好地工作。

示例

[我在快速Nanao浏览器示例上做了很多工作,使它更简短,并准确地指出了问题出在哪里以及我如何解决它。

我正在使用的代码段为以下代码段:

main.cpp

#include <QtQml/QQmlApplicationEngine>
#include <QtQml/QQmlContext>
#include <QtWebEngine/qtwebengineglobal.h>
static QUrl startupUrl()
{
    QUrl ret;
    QStringList args(qApp->arguments());
    args.takeFirst();
    for (const QString &arg : qAsConst(args)) {
        if (arg.startsWith(QLatin1Char('-')))
             continue;
        ret = Utils::fromUserInput(arg);
        if (ret.isValid())
            return ret;
    }
    return QUrl(QStringLiteral("https://123.456.789.123:7878"));
}

int main(int argc, char **argv)
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QtWebEngine::initialize();
    Application app(argc, argv);
    QQmlApplicationEngine appEngine;
    Utils utils;
    appEngine.rootContext()->setContextProperty("utils", &utils);
    appEngine.load(QUrl("qrc:/ApplicationRoot.qml"));
    if (!appEngine.rootObjects().isEmpty())
        QMetaObject::invokeMethod(appEngine.rootObjects().first(), "load", Q_ARG(QVariant, startupUrl()));
    else
        qFatal("Failed to load sources");
    return app.exec();
}

ApplicationRoot.qml

import QtQuick 2.1
import QtWebEngine 1.9
QtObject {
    id: root
    property string script_password: "
        setTimeout(function(){
            var input_password = document.getElementsByName('password')[0];
            input_password.value = '%1';
            var button = document.getElementById('passwordNext');
            button.click();
            }, 100);
            ".arg(password)

    property QtObject defaultProfile: WebEngineProfile {}
    property QtObject otrProfile: WebEngineProfile {
        offTheRecord: true
    }
    property Component browserWindowComponent: BrowserWindow {
        applicationRoot: root
        onClosing: destroy()
    }    
    function createWindow(profile) {...}
    function createDialog(profile) {...}
    function load(url) {...}
}

BrowserWindow.qml

import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.0
import QtQuick.Window 2.1
import QtWebEngine 1.9

ApplicationWindow {
    id: browserWindow

    property string password: "abcdefghilmno"

    property QtObject applicationRoot
    property Item currentWebView: tabs.currentIndex < tabs.count ? tabs.getTab(tabs.currentIndex).item : null
    property int previousVisibility: Window.Windowed
    width: 1300
    height: 900
    visible: true
    title: currentWebView && currentWebView.title
    Component.onCompleted: flags = flags | Qt.WindowFullscreenButtonHint
    toolBar: ToolBar {...}
    // Necessary to accept server's certificate
    TabView {...}
    // Showing Manager Window
    WebEngineView {
        id: devToolsView
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        onNewViewRequested: function(request) {
            var tab = tabs.createEmptyTab(currentWebView.profile);
            tabs.currentIndex = tabs.count - 1;
            request.openIn(tab.item);
        }
    }
    // By-Passing the Server's Certificate using sslDialog
    MessageDialog {...}
    DownloadView {
        id: downloadView
        visible: false
        anchors.fill: parent
    }
    function onDownloadRequested(download) {
        downloadView.visible = true;
        downloadView.append(download);
        download.accept();
    }
}

非常感谢您提供有关如何解决此问题以及如何继续前进的指导。

[了解了如何将JavaScript函数集成到Qt-QML中之后,我现在尝试将我以前的文章中所学到的内容应用于实验室中的一个小实例。我正在尝试访问...

javascript qt qml qt5 qwebengineview
1个回答
0
投票

下一次,有必要显示您自从说不起作用并且使用我之前的代码是不够的以来所尝试的,每次登录都取决于每个系统,因此没有通用的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.