Closing a web page after submit - lotus-notes

I want to close a document after someone has updated it.
I tried the following javascript in the submit button:
document.forms[0].submit();
window.close()
But the web-query-save agent doesn't fire then. But if I comment out the 'close', the WQS agent executes as expected but then I have the dreaded "Form Processed" page. I supposed I could but a nice page up but I'd like to just close the page. Any thoughts?
thanks
clem

At the end of your WebQuerySave Agent you can print a message to output some javascript.
Print |<script type="text\javascript">|
Print |window.close();|
Print |</script>|

I know this is 9 years old, but this solution didn't work for me.
Instead, I end my webquerysave agent with a Print statement back to the same document:
Print "[" + webDbPath + "/0/" + currdoc.Universalid + "?EditDocument&saveSuccess=true]"
I can then check for the saveSuccess in the URL on the onload and if found, close the window with: window.open('','_self').close();

Related

How to Know an Alert Pop-Up Has Occurred

I am automating a website. I am using SeleniumBasic in Excel VBA.
I have a simple Pop-Up, or Alert, with an OK button.
I cannot access the Pop_Up by using Inspect so I have no HTML to show.
When the Pop-Up occurs, I respond with Driver.SwitchToAlert.Accept. It goes away, as desired.
I don't know how to check programmatically if the Pop-Up is present.
If I assume that the Pop-Up may have occurred and use this code on a just-in-case basis, i.e. use the code without the Pop-Up existing, the program stops without any error message.
Is there a way to check if the Pop-Up window exists before I respond?
Well, I found the answer:
I got this code from someone who got it from someone else.
Private Function AlertIsPresent() As Boolean
'Returns true if an alert is present, false otherwise
Dim T As String
On Error Resume Next
T = Driver.Title 'This raises error 26 if an alert(pop-up) is displayed
AlertIsPresent = (26 = Err.Number)
End Function
If function returns 'true', use the Driver.SwitchToAlert.Accept to close it.

How to set window.alert when redirecting

I'm crawlling some web pages for my research.
I want to inject javascript code below when redirecting to other page:
window.alert = function() {};
I tried to inject the javascript code below using WebDriverWait, so that selenium may execute the code as soon as the driver redirect to new page. But It doesn't work.
while (some conditions) :
try:
WebDriverWait(browser, 5).until(
lambda driver: original_url != browser.current_url)
browser.execute_script("window.alert = function() {};")
except:
//do sth
original_url = browser.current_url
It seems that the driver execute javascript code after the page loaded because the alert that made in the redirected page is showing.
Chrome 14+ blocks alerts inside onunload (https://stackoverflow.com/a/7080331/3368011)
But, I think the following questions may help you:
JavaScript before leaving the page
How to call a function before leaving page with Javascript
JavaScript before leaving the page
I solved my problem in other way.
I tried and tried again with browser.switch_to_alert but it didn't work. Then I found that it was deprecated, so not works correctly. I checked the alert and dismiss it in every 1 second with following code :
while *some_condition* :
try:
Alert(browser).dismiss()
except:
print("no alert")
continue
This works very fine, in Windows 10, python 3.7.4

How to sendKeys wherever the cursor is in selenium nodejs

I have created a script to comment in facebook posts, I did clicked on comment box, and cursor do appears but unable to perform .sendKeys()
here's my code:
var commentBox = driver.findElement(By.xpath('//*[#id="addComment_'+this.postIdSlice+'"]/div/div[2]/div/div/div/div[1]/div'));
actions.mouseMove(commentBox).click().perform();
driver.sleep(2000);
actions.sendKeys("Hello").perform();
but when I execute it doesnt sends 'Hello' to comment box.
PS: that postIdSlice is id of the post, no issues there just want to push/send string in that commentbox.
Use the Xpath to click on the comment box, then you can use the ActionSequence to sequnce input and ENTER key.
let action = new webdriver.ActionSequence(driver);
action.sendKeys("comment");
action.sendKeys(Keys.ENTER);
action.perform()

How do I find out if a watir object's browser is closed or not? (after typing ctrl+C or otherwise)

When I close the browser watir has been using (or hit ctrl+C and close it out that way), I get these types of errors...
b = Watir::Browser.new
#ctrl+C and closes browser window
b.url
Errno::ECONNREFUSED: Connection refused - connect(2)
...when I run something like #url or #goto on the watir object.
I tried methods like #closed? and #closed on the object, but they aren't recognized. Have also tried this:
b.methods - Object.methods
and perused the available methods but nothing has worked so far.
Short of responding to raised error messages with begin/rescue blocks, what methods can I use to determine if the browser window is closed?
A bonus would be a method that would allow me to reinitialize the browser window, keeping any preferences picked up along the way. That would be the best possible solution.
Use exists? method to check whether browser is closed or not, browser.exists? would true if browser is open, If not, it would return false.
Going to answer my own question here because I'm not sure if a straightforward answer is possible. Monkey-patching time.
class Watir::Browser
def try(meth)
begin
self.send(meth.to_sym)
true
rescue
false
end
end
def open?
if try(:exists?)
exists?
else
false
end
end
end
Works no manner which way you closed your browser window.
I may submit a pull request
The correct way to close the browser is browser.quit or browser.close
Then you can call browser.exists? and it will return false. Sending ctrl+C exits your session entirely, so there is no longer anything listening at the url/port you are making calls to, and you will always get that error.

How to click on onbeforeunload prompt in Watir test?

I have a webpage that has an onbeforeunload script that prompts the user when they take an action that would navigate away from the current page.
How do I interact with this popup using Watir? My current approach looks like this:
$ie.link(:text, 'Dashboard').click_no_wait
hwnd = $ie.enabled_popup(10)
assert(hwnd, 'The expected \'leave this page?\' popup was not shown')
win = WinClicker.new
win.makeWindowActive(hwnd)
win.clickWindowsButton_hwnd(hwnd, "OK")
The problem is that if I use "click no wait" the popup is not created, and the test times out. If I use "click" then the popup is created, but the test hangs after it opens.
Any suggestions?
Do you want to assert dialog message?
I try your code, but could not find solution.
This is to try to catch dialog then when popup,get msg while 5sec. polling per 1sec.
$ie.link(:text, 'Dashboard').click_no_wait
#autoit = WIN32OLE.new('AutoItX3.Control')
5.times do
if #autoit.WinWait('Windows Internet Explorer','',1)==1 then
#autoit.WinActivate('Windows Internet Explorer',"")
#dialog_text = #autoit.WinGetText('Windows Internet Explorer',"")
dialog_pop = "YES"
break
else
sleep(1)
dialog_pop = "NO"
end
end
This should do the trick closing this alert:
browser.alert.ok
See the Watir docs here.

Resources