我的RPA Express项目遍历多个URL,如果满足特定条件,请单击图标,该图标会弹出HTML“确认”模式对话框。该代码单击“确定”(也尝试按“ Enter”键),然后进入下一个URL。 问题在于,在对话框上的第一个确认(单击“确定”或按Enter)并处理到下一个URL后,所有使用Web元素(通过xpath获取)的尝试都会失败,并显示以下内容:
原因:org.openqa.selenium.NoAlertPresentException:当前未打开任何模式对话框
我尝试失败:
系统似乎无法识别出模态对话框实际上已关闭。 知道如何解决它吗?
这是主循环代码:
event_id_list.each( {this_event_id ->
this_id = RString.of(RNumber.fromRepresentation("${this_event_id}","0;pl-PL").toRepresentation("0;pl-PL"))
this_url = event_url_patern.replaceFirstIgnoreCase("[id]", "${this_id}")
confirm_close_window = RBoolean.fromCanonical("false")
sleep(1000)
inDesktop {
sendKeys(StringTransformations.getKeyPressText(63, 0, 116, 2))
}
// Group of actions: Open Event URL
$(byImage("1536237127355-anchor-1536911026524.apng", Integer.valueOf(0), Integer.valueOf(0))).click()
setClipboardText(this_url as String)
inDesktop {
sendKeys(StringTransformations.getHotKeyText(97, 2))
}
inDesktop {
sendKeys(StringTransformations.getHotKeyText(118, 2))
}
inDesktop {
sendKeys(StringTransformations.getKeyPressText(28, 13, 10, 0))
}
def i1 = System.currentTimeMillis() + 8000
boolean i0 = true
while (i0) {
try {
$(byImage("1536912304113-anchor.apng")).getCoordinates()
even_opened = RBoolean.TRUE
break
} catch (Exception ignored) {
even_opened = RBoolean.FALSE
}
i0 = System.currentTimeMillis() < i1
}
$(byImage("1537167271142-anchor-1537167271149.apng", Integer.valueOf(0), Integer.valueOf(0))).click()
try {
this_crewx_vessel = RString.of($(byXpath("/html/body/form/div[3]/table[1]/tbody/tr[1]/td[2]/b")).text())
} catch (Exception i2) {
this_crewx_vessel = RString.of("N/A")
}
try {
this_crewx_port = RString.of($(byXpath("//*[@id=\"form1\"]/div[3]/table[1]/tbody/tr[1]/td[6]/b/a")).text())
} catch (Exception i3) {
this_crewx_port = RString.of("N/A")
}
sleep(4000)
Resource.append("${log_file_path}", "<p>Processing id ${this_id} (${this_crewx_vessel} at ${this_crewx_port}) - outcome: ", "UTF-8")
icon_src = RString.of($(byXpath("//*[@id=\"toggleEventImg\"]")).getAttribute("src"))
if ((RString.of("images/lock.gif")) in (icon_src)) {
$(byXpath("//*[@id=\"toggleEventImg\"]")).click()
def i5 = System.currentTimeMillis() + 3000
boolean i4 = true
while (i4) {
try {
$(byImage("1536910894370-anchor.apng")).getCoordinates()
confirm_close_window = RBoolean.TRUE
break
} catch (Exception ignored) {
confirm_close_window = RBoolean.FALSE
}
i4 = System.currentTimeMillis() < i5
}
if ((confirm_close_window) == (RBoolean.fromCanonical('true'))) {
inDesktop {
sendKeys(StringTransformations.getKeyPressText(28, 13, 10, 0))
}
sleep(4000)
Resource.append("${log_file_path}", "closed.</p>", "UTF-8")
// compare_item = RString.of($(byXpath("//*[@id=\"toggleEventImg\"]")).text())
} else {
sleep(4000)
Resource.append("${log_file_path}", "no action (confirm window no show)</p>", "UTF-8")
}
} else {
sleep(4000)
Resource.append("${log_file_path}", "no action (already closed).</p>", "UTF-8")
}
})
错误抛出于:
icon_src = RString.of($(byXpath("//*[@id=\"toggleEventImg\"]")).getAttribute("src"))
答案 0 :(得分:0)
请尝试使用OpenIE或OpenChrome打开URL,而不是单击图像并输入url
openIE(UrlOperations.ensureProtocol("${this_url}"))