【问题标题】:How to extract data from Google Chrome JavaScript Alert Popup using UiPath如何使用 UiPath 从 Google Chrome JavaScript 警报弹出窗口中提取数据
【发布时间】:2019-07-04 03:36:33
【问题描述】:

我想提取文本,然后使用 UiPath 在 Google Chrome JavaScript 警报弹出窗口中单击一个按钮。

具体来说,我遇到以下问题:

  1. 定位对话框的选择器是什么?如何找到它?
  2. 从对话框中定位和提取文本的选择器是什么?如何找到它?
  3. 在对话框中单击“确定”按钮的选择器是什么?如何找到它?

我知道,对于网络自动化,UiPath 建议在大多数情况下使用 IE,因为 UiPath 可以使用其浏览器 COM 对象以更“原生”的方式与它交互。其他浏览器会有限制,并且在版本更新的情况下可能会遇到困难。但是,在某些情况下无法使用 IE,例如在我的工作中,我们与 Google 签订了工作协议,而我们的许多内部网站无法在 IE 中运行。

要完成 UiPath 3 级高级认证(在线):作业 2 - 生成年度报告,您必须创建一个机器人来执行以下操作:

  • 导航到https://acme-test.uipath.com/
  • 使用用户名和密码登录
  • 点击各种元素在系统中导航
  • 交互并从 JavaScript 警报弹出窗口中提取数据

问题是 UiExplorer 找不到正确的选择器,这使得很难从谷歌浏览器弹出窗口中获取文本,因为它的呈现方式与 IE 不同,并且没有公开文本属性(其中其他的)。这是来自 acme-test 站点的 sn-p,用于创建警报以帮助定义选择器,这里是 UiPath XAML file

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>

<head>
  <title>Upload reports</title>
</head>

<body>
  <!-- Page Content -->
  <div class="container">
    <button type="button" class="btn btn-primary" id="buttonUpload">Upload Report</button>
    <script type="text/javascript">
      jQuery(document).ready(function() {

        $('input[type=file]').on('change', prepareUpload);

        function prepareUpload(event) {
          files = event.target.files;
          $('#upload-file-info').html(files[0].name)
        }

        jQuery('#buttonUpload').click(function(event) {
          event.stopPropagation(); // Stop stuff happening
          event.preventDefault(); // Totally stop stuff happening

          var vTaxID = jQuery('#vendorTaxID').val();
          var rYear = jQuery('#reportYear').val();

          // If nothing is filled
          if (vTaxID == "" || rYear == "") {
            alert('Plase fill in the Vendor TaxID and Report Year!');
            return;
          }

          if (typeof files === 'undefined') {
            alert('Please select the Report File');
            return;
          }

          // Create a formdata object and add the files
          var data = new FormData();
          jQuery.each(files, function(key, value) {
            data.append(key, value);
          });

          console.log('...');

          jQuery.ajax({
              url: "/cmajax.php?cmd=uploadReport&cvTaxID=" + vTaxID + "&crYear=" + rYear,
              type: "POST",
              data: data,
              cache: false,
              dataType: 'json',
              processData: false, // Don't process the files
              contentType: false, // Set content type to false as jQuery will tell the server its a query string request
            })
            .always(function(msg) {
              console.log('done');

              if (msg.responseText == 'bad')
                alert("Some problems were encountered.");
              else {
                console.log(msg);
                alert('Report was uploaded - confirmation id is ' + msg.responseText);
              }
            });
        })
      });
    </script>
  </div>
</body>

</html>

【问题讨论】:

    标签: javascript google-chrome popup rpa uipath


    【解决方案1】:

    以下可能不是您正在寻找的内容,但它可能会提供替代解决方案。在大多数 RPA 工具中自动化警报可能有点麻烦,所以我喜欢使用警报覆盖技巧

    基本上,您注入一个函数,该函数将覆盖默认警报函数(显示弹出窗口)并将其内容重新路由到 UiPath 可访问的某个位置,例如自定义文本框。

    更详细地说,您在某处创建一个文本框...

    var body = document.getElementsByTagName("body")[0];
    var text = document.createElement("input");
    text.id = "alertOutput";
    body.insertBefore(text, body.firstChild);
    

    ...然后用消息重新路由覆盖警报功能。

    function alert(message) {
        var text = document.getElementById("alertOutput");
        text.value = message; // or .innerText
    }
    

    现在页面上的每个警报都会将其内容直接发送到文本框,而不是显示弹出窗口。

    PS:我故意不在我的代码中使用jQuery,但是看到它在您的网站上可用,您可以利用它。

    【讨论】:

    • 感谢您的回答。从 JS 的角度来看,这确实是合乎逻辑且出色的。我相信它会帮助很多用户,但正如你自己指出的那样,这是一种解决方法。我希望你不介意我暂时保留这个问题,看看是否有人有解决这个问题的“本地”UiPath 方法,这对我和 UiPath 社区都有帮助
    【解决方案2】:

    我设法提取信息并继续使用: * 整个 chrome 窗口上的“获取 OCR 文本”(在未显示弹出窗口时使用指示元素,因为这似乎会给我的机器上的 UIPath studio 带来问题)并在“分配”活动中使用字符串操作获取我需要的文本。 * “发送热键”进入chrome窗口关闭弹出窗口

    我在默认设置下使用了 Google OCR(英语、比例 2、...)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 1970-01-01
      相关资源
      最近更新 更多