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.
href = "javascript:alert('test');"
created the alert as expected. Perhaps you are seeing some browser compatibility issues? For example,href = "javascript:alert();"
(note the no parameter being passed to alert()), in IE will display the alert with no message where as in Firefox it will do nothing. Does clicking the area manually work as expected in Firefox? – Perfectionism