Search code examples
javawatij

WebSpec (Watij) can't click a button


I'm working on a simple app that utilizes WebSpec. I'm utilizing the mozilla() browser. Now, there is one page where I want to inject some text into an input and then click a button with the value "Submit". The page is loaded properly, all of the Tags are present and can be accessed. The only trouble is, the "Submit" button doesn't work every time when WebSpec tries to access it. I can't make it work even when I click it on my own. The page needs to be reloaded.

Here's the code of the form:

<form action="" method="post" name="theForm" id="theForm" onsubmit="get_search_results(); return false;">
  <table cellpadding="0" cellspacing="10" style="text-align:left;margin:auto;" >
    <tr>
      <th valign="top">Enter Text: </th>
      <td valign="top"><input type="text" name="theText" id="theText" class="box"  value="" />
      <br />
      </td>
      <td valign="top">
        <select name="its-name" class="box" >
                //some options
        </select>
      </td>
      <td valign="top"><input type="button" value="Submit" class="button-of-color" onclick="get_the_results();"  /></td>
      <td valign="top"><a href="url" class="button-of-color">A Link</a></td>
    </tr>
  </table>
  <div id="theResults"></div>
</form>

And here's the code I'm using to perform said actions (XTend code):

spec.open(theUrl)
val keywordBox = spec.find.input().with.name("theText")
val proceedBox = spec.find.input().with.type("button").with.value("Submit")
keywordBox.set.value(theText)
proceedBox.click

The input text field gets its value, but the button (even though it's being clicked), won't perform the script. As I said, even clicking manually doesn't have any effect. On the other hand, I can change its value and other properties.

I have no idea why this happens and what can be the culprit. And since another app I've written in .NET using Watin works perfectly, I'm sure it should work.

Thanks in advance for your help. :)

EDIT: Just chaning mozilla to ie seems to be solving the problem. I suppose it's a bug that should be fixed by the developers. I'll ask them. What I don't like about this is, this is why I switched to Java from .NET -- that I wouldn't have to port appliactions.

In the meantime, I'm still looking for a workaround...


Solution

  • I had the same problem with IE, & added a while loop to check if the text field i set was done, [not a fix, and yes, a dirty workaround]

    Ex:

        ie.textField(name, "email").set("[email protected]");
        while (ie.textField(name, "email").value().isEmpty())
            ;       
        ie.button(name, "Login").click();