My RPA Express project iterates through a number of URLs and if a certain condition is met, clicks on a icon that pops up a HTML "Confirm" modal dialog. The code clicks "OK" (tried also Keypress "Enter") and then goes into a next URL. The problem is that after the first confirmation (click OK or press Enter) on the dialog box and processing to a next URL, all attempts to use Web Element (get by xpath) fail with:
Caused by: org.openqa.selenium.NoAlertPresentException: No modal dialog is currently open
I tried unsuccessfully:
- to "CTRL+F5" the page on reload
- set focus on the page (with MouseClick) after reload
It looks like the system does not recognize that the modal dialog was actually closed. Any idea how to get it fixed?
Here is the main loop code:
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")
}
})
The error is thrown at:
icon_src = RString.of($(byXpath("//*[@id=\"toggleEventImg\"]")).getAttribute("src"))
Instead of clicking an image and typing in the url, try opening the URL using OpenIE or OpenChrome