Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Watir-Webdriver support clicking on links where the destination is a javascript?

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.

like image 452
Phuule Avatar asked Nov 13 '12 16:11

Phuule


People also ask

What is Watir used for?

Definition: Watir, pronounced as water, is a group of Ruby libraries for automated web browsers. It allows writing the tests which are easy to read and maintain. In other words, it is a simple and flexible tool. Description: Watir drives the browsers the same way as people do.

What is Watir selenium?

Watir is an open-source web application testing framework that is designed to make writing Selenium tests simple and efficient. Built on Selenium's Ruby language bindings, Watir is able to drive the browser in the same way humans do.

Is Watir a test management tool?

Watir is one of the best regression testing tools as writing, maintaining/updating and executing test cases are easy.


1 Answers

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!

like image 100
Phuule Avatar answered Nov 15 '22 08:11

Phuule