如何使用UiPath从Google Chrome JavaScript Alert Popup中提取数据

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

我想提取文本,然后使用UiPath点击Google Chrome Javascript Alert弹出窗口中的按钮。

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

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

我知道对于Web自动化,UiPath建议在大多数情况下使用IE,因为UiPath可以使用其浏览器COM对象以更“原生”的方式与其进行交互。其他浏览器将有限制,并且可能在版本更新时遇到困难。但是,在某些情况下,不可能使用IE,就像在我的工作中我们与Google达成协议工作,我们的许多内部网站都不能在IE中工作。

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

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

问题是UiExplorer无法找到正确的选择器,这使得很难从Google Chrome弹出窗口中获取文本,因为它的呈现方式与IE浏览器不同,并且不会显示文本属性(以及其他) 。以下是acme-test网站的片段,用于创建警报以帮助定义选择器,这里是一个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
2个回答
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,但看到它在您的网站上可用,您可以利用它。


1
投票

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

我在默认设置上使用了Google OCR(eng,scale 2,...)

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