3
votes

I'm new to Watir and I'm trying to click the following login button:

<div class="container login" style="display: table;">
    <div class="left">
    <div class="right">
        <div class="joinbox">
            <form id="form_login" class="hidden-submit" method="post">
                <input type="submit" value="Submit">
                <div class="header">
                    <div class="left">
                    <div class="mid">
                    <div class="right">
                       <a class="button button-red submit" href="#">Log In</a>
                    ...

So far I'm able to access this button by going through every nested div:

b.div(:class, "container login").div(:class, "right").div(:class, "joinbox")......

and so on. Is this really the best way to access this button? I assume I'm missing something. Any help is appreciated!

3
work with the element itself if there is an easy unique identifier. otherwise work with the lowest level 'container' such as a div or span you can easily identify and then specify the link within that element e.g. browser.div(:how, what).link.click - Chuck van der Linden
Am I missing something too, or can you not just go b.button(:value=>'Submit')? I'm on watir-webdriver now, maybe I've forgotten something. - kinofrost
@kinofrost: you could if there was such a button on the page, but in this case it is a link - Željko Filipin
@ŽeljkoFilipin I have spotted my mistake, I see the button (link) he's on about now, I was looking too far up the tree. Ignore me! :) - kinofrost

3 Answers

2
votes

If there is only one link (that looks like a button) with text Log In on the page, try this:

browser.a(:text => "Log In").click

You could also use class attribute:

browser.a(:class => "button button-red submit").click
0
votes

May this work? browser.form(id,form_login).submit BTW: I have seen some tips said safari only support GET mode for submit.

-1
votes

I would try: browser.a(:href => "#").click

Assumption - "#" is unique. may need a slash so it doesn't misinterpret the #. I used something similar when I was trying to reference a button with only a href value of "/login" e.g., browser.a(:href => "/login").click.