I'm using watir-webdriver and i'm having trouble with a confirmation popup. I click on a 'Sell' button and a confirmation popup appears. I can't seem to figure out how to come up with the step to click 'OK' on the popup. Any help would be much appreciated.
The html in question is: (Button)
<button>class="btn primary" onclick="return confirm('Are you sure you wish to sell the selected loan parts?');" value="Sell Loan Parts" name="sell_loan_parts" style="" type="submit"</button>
I tried using following step, but I guess this is incorrect:
#browser.button(:onclick, "return confirm('Are you sure you wish to sell the selected loan parts?');").click
Error message I recieve is:
Modal dialog present (Selenium::WebDriver::Error::UnhandledAlertError)
[remote server] file:///var/folders/fd/hjkxr06j6gs6620tl4k_9fh00000gn/T/webdriver-profile20121129-50930-ul24fl/extensions/fxdriver#googlecode.com/components/command_processor.js:10402:in `unknown'
Watir has an api for handling these types of javascript alerts. Some useful links:
Watir-Webdriver > Javascript Dialogs
Watir-Webdriver Alert API
You should be able to click OK in the confirm by doing:
#browser.alert.ok
Might also be of help to recall the browser to set focus to the modal window (when using Selenium Webdriver and Cucumber, for example). This has worked for me in the past when nothing else has. All you have to do is this:
browser = GemName::CucumberFormatter::Browser.get_browser
browser.alert.ok
It's just another option.
Related
I have modal flow in my Slack App. I have some issues with the end of the flow however.
Basic idea of the flow. You get a Modal, you do a selection, you get another modal, you perform an action and then Modal disappears.
I have tried two different ways both with problems but with different result
Flow 1: response_action: "update"
You press a button on home tab that opens a modal with bot.views.open
You make a selection
In the response I send {response_action: 'update', view: }
User gets the new Modal without any errors. They then click a button.
Now I would like the modal to disappear. So on the result of the action I send {response_action: 'clear'}
Nothing happens :(. I would like the modal to disappear of course :)
Flow 2: bot.views.update
You press a button on home tab that opens a modal with bot.views.open
You make a selection
I create the same view as above but I run bot.views.update{view_id: , view: }
New view comes up however it has an error in the top: We had some trouble connecting. Try again?
Now I would like the modal to disappear. So on the result of the action I send {response_action: 'clear'}
Nothing happens :(. I would like the modal to disappear of course :)
So second flow has annoying error but same result with not disappearing.
Feels like Im missing something here.
Somebody have an Idea what Im missing?
Using Apex 5.1.3
I have everyting working, but I have a requreimet to refresh the entire page (parent page) on the close of the modal page or press submit button.
I have tried quite a few things in dynamic actions on the parent page etc, but nothing is working.
How can I get the parent page to fully refresh when the modal dialog is submitted and closed.
Your help would be most appreciated.
Regards,
Morshed
You could either place a branch after processing on your modal that redirects to the parent page, or create a dynamic action 'on dialog close' on the button/region that invokes the dialog page, which then submits/refreshes the page.
If you think 'nothing is working', put APEX in debug mode, open your browser console, and check if the dynamic actions are actually firing.
I have a page from which modal dialog page gets opened. After page is opened, the user makes some selections and clicks on the button and some javascript gets executed. After it is done, I need to close the modal page. I tried window.close() but it did not work. How can I close the modal dialog page from javascript?
Try this:
apex.navigation.dialog.close(true)
https://docs.oracle.com/cd/E59726_01/doc.50/e39149/javascript_api.htm#AEAPI30096
I have rarely seen the documentation on the method below. I had to read a book to find out.
Try this:
redirect to URL:
javascript:closeModal();
You can also pass the modal parameter if necessary:
javascript:closeModal('P2_HELP_MODAL');
You can also open the same way:
javascript:openModal('P2_HELP_MODAL');
I am using web-watir to drive phantomjs. I am trying to submit a bunch of forms(POST) on the webpage. I have all the forms in a collection. When I click the submit button and browser.back(), I get Selenium::WebDriver::Error::StaleElementReferenceError. I tried using form.submit() but same issue of going back and getting StaleElementReferenceError. I tried to submit the form in another page (browser.execute_script( "window.open(page)" )) but I don't think that will submit my form (if the form was a GET, that might have worked). I tried Net::HTTP.post_form() which is separate from the phantomjs session (did not work, I need to be logged in).
I am out of ideas except find the elements all over each time I navigate back. I guess I could replace phantomjs with Chrome or Firefox. Tell me, is there a way to submit the form in a new page phantomJS?
Here is some code:
forms = browser.forms()
forms.each{ | form |
form.submit()
browser.back()
}
If submitting each form brings you to another page, then it is expected that you get a StaleElementReferenceError for any previously saved elements. This is how Selenium-WebDriver was designed, so the problem will still exist if you switch to Chrome or Firefox.
Given that you are iterating through each form, it would be easy to locate each form by index:
browser.forms.length.times do |i|
browser.form(index: i).submit
browser.back
end
The above code took the same approach of directly submitting the form. However, if possible, the submit button should be clicked. Directly submitting the form may bypass important code that is tied to the action of clicking the submit button.
I am new to Ruby and Watir-Webdriver. I have a suite of automation for our site written in VBScript and I want to convert it to Ruby/Watir because I now have to support Firefox. I've found I really like Ruby, and I'm working on Watir, but I've spent a week now trying to get Webdriver to even display my login screen.
The site begins with a "Warning screen" with an "I agree" area. The user click on the I agree and is presented with a login screen.
<body onload="showMessage('true')"><div id="login"><div id="message"><map name="accept">
<area href="javascript:showLogin();" shape="rect" coords="280,390,384,432" />
</map></div></div></body>
I need to click the area to present the login screen (which is the same page, a form really, just hidden). I do this all day long with VBScript:
objExplorer.Document.GetElementsByTagName("area")(0).click
However, using Watir-Webdriver, browser.area(:index, 0).click does nothing.
puts browser.area(:index, 0).shape
=>RECT
puts browser.area(:index, 0).coords
=>280,390,384,432
So, I know the script can "see" the area element and read its attributes. It just doesn't do anything with the click event.
If I use a browser.goto on the href itself:
browser.goto("javascript:showLogin();")
the login becomes visible, but I cannot interact with the elements (set the text fields for user name and password). I'm looking at the page with the developer tools window open (to view the HTML) and it just says "Loading...".
This is where I am stuck. Interestingly, if I use the login form's name and do a:
browser.form(:name, "LoginForm").submit
I get the popup message from the form that the user name and password are blank, so there is still some interaction.
Of course, if I manually enter the user name/password, I can submit the form fine even if it says "Loading...".
I understand "when_present.click" and other techniques for waiting for the browser; these don't work. My dilemma is I can't click the area, and if I use the goto on the javascript, the browser then ignores the automation from Watir.
Thanks for your help. Even an answer of "Sorry, Watir or Webdriver won't do this" is acceptable to me. It will allow me to move on and look for other solutions.
Edit after questions in comments:
Sorry, the site is not public, so I can't post a link.
As for working in Firefox, the script works just fine. IE is having the issue. The comments got me thinking: I do get a "...certificate not issued by trusted..." certificate error upon first navigating to the site. Could the certificate error I get in IE cause some sort of disconnect to the automation before presenting the form? I use a line I got here on stackoverflow to click past the cert error:
browser.goto("javascript:document.getElementById('overridelink').click()")
But now I think maybe this might be a part of the issue. I have gone to my IE (using IE 9) options and unchecked the security options for checking certs, but to no avail. If this may be causing the issue, I'll have to go negotiate with the infrastructure team to generate certificates for us to download each time they build a new server.
Ok, I guess after reading hundreds of posts and hours of Google searches I finally found a solution to my issue: browser.execute_script.
browser.execute_script("showLogin();")
It was that simple. Using browser.goto hung on loading the page and webdriver timed out. Using execute_script works perfectly!