gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:10:08 25 4
gpt4 key购买 nike

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

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

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

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

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

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

问题是 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>

最佳答案

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

基本上,您会注入(inject)一个函数,该函数将覆盖默认警报函数(显示弹出窗口)并将其内容重新路由到 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,但看到它在您的网站上可用,您可以利用它。

关于javascript - 如何使用 UiPath 从 Google Chrome JavaScript Alert Popup 中提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54617056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com