【发布时间】:2019-07-04 03:36:33
【问题描述】:
我想提取文本,然后使用 UiPath 在 Google Chrome JavaScript 警报弹出窗口中单击一个按钮。
具体来说,我遇到以下问题:
- 定位对话框的选择器是什么?如何找到它?
- 从对话框中定位和提取文本的选择器是什么?如何找到它?
- 在对话框中单击“确定”按钮的选择器是什么?如何找到它?
我知道,对于网络自动化,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