0

我的 RPA Express 项目会遍历多个 URL,如果满足某个条件,单击一个图标会弹出一个 HTML“确认”模式对话框。代码单击“确定”(也尝试按“Enter”),然后进入下一个 URL。问题是,在对话框上第一次确认(单击 OK 或按 Enter)并处理到下一个 URL 后,所有使用 Web Element(通过 xpath 获取)的尝试都失败了:

引起:org.openqa.selenium.NoAlertPresentException:当前没有打开模式对话框

我尝试不成功:

  • 重新加载页面时“CTRL+F5”
  • 重新加载后将焦点设置在页面上(使用 MouseClick)

看起来系统无法识别模式对话框实际上已关闭。知道如何修复它吗?

这是主循环代码:

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"))
4

1 回答 1

0

不要单击图像并输入 URL,而是尝试使用 OpenIE 或 OpenChrome 打开 URL

openIE(UrlOperations.ensureProtocol("${this_url}"))
于 2018-09-20T13:01:58.187 回答