0

Unable to click on a button/link on mobile view (iOS) via Appium using Capybara

My setup:

I'm testing a website on the mobile view (iOS). On Desktop it works fine (using Capybara), but when I test on mobile view (iOS) via Appium using Capybara the test gets stuck on a button, that is visible but Capybara is unable to click it.

The HTML:

<div id="HeaderContent" class="accordion-content" style="display: block;">        

<div id="CompMessageContainer" class="content row hidden">
    <div role="alert" aria-atomic="true" aria-relevant="all" aria-live="assertive">
        <div class="uiMessaging alert-box radius success" id="ui-alert-message">
            <div>
                <div>
                    <div class="positiveCompMessageIcon"></div>
                </div>
                <div>
                    <div id="CartAlertMessage">

                    </div>
                    <ul id="cartAlertMessageDetails" class=" hidden">                            
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="milAndFirstRespContent">
    <div id="cartBottomAlternateDiscountOptions">
        <div id="compText">
            Random Text.
        </div>
        <div class="desktopComp-btn-container">
            <a id="imgMil" href="#" class="login-trigger left utrack" data-scope="mil" data-track-event="CompTrigger">
                <div class="desktopCompMilBtn"></div>
            </a>
            <a id="imgResp" href="#" class="login-trigger left utrack" data-scope="responder" data-track-event="CompTrigger">
                <div class="desktopCompRespBtn"></div>
            </a>
            <div class="desktopCompLogo"></div>
            <div id="desktopCompVerified" class="hidden">
                <div class="desktopCompVerified"></div>
                <div id="desktopCompStatus">&nbsp;Status Verified</div>
            </div>
        </div>
        <div>

        </div>
    </div>
</div>
    </div>

My attempts to click the <div class="desktopCompMilBtn"></div> button or a id="imgResp" element.

pry(#<Object>)> find("div.desktopCompMilBtn").visible?
=> true

pry(#<Object>)> find("div.desktopComp-btn-container").visible?
=> true

pry(#<Object>)> find("div.desktopComp-btn-container").find("div.desktopCompMilBtn").visible?
=> true

pry(#<Object>)> find("div.desktopComp-btn-container").find("div.desktopCompMilBtn").click
=> nil

pry(#<Object>)> find("div.desktopComp-btn-container").find("a#imgMil").visible?
=> true

pry(#<Object>)> find("div.desktopComp-btn-container").find("a#imgMil").click
=> nil

pry(#<Object>)> find("div.desktopComp-btn-container").find("a#imgMil").find("div.desktopCompMilBtn").click
=> nil

Unfortunately nothing has worked thus far in being able to click the button. By the way the button is supposed to open up a new window, not sure if that matters or not.

Farooq
  • 1,925
  • 3
  • 15
  • 36
  • Are you assuming that click will return something different if it clicks the element? – Thomas Walpole Nov 18 '15 at 21:48
  • Hmmm...nope...it should click like a regular link/button...which in turn is supposed to open a new window – Farooq Nov 18 '15 at 22:07
  • Ok -- so rather than showing that click returns nil (which does not indicate an error since it very well may when successfully clicking something) please show the test and failure that you're actually having, along with the JS that should be triggered by the click – Thomas Walpole Nov 18 '15 at 22:11
  • Well technically there is no failure, I just can't get Capybara to open up the window after it clicks on that button, which leads me to believe it's not clicking on it or not the proper element? – Farooq Nov 18 '15 at 22:27
  • 1
    My guess is that it is clicking it, but the action is blocked by Safari - see my answer below – Thomas Walpole Nov 18 '15 at 23:02
  • Tom, thanks so much, this comment of your's led me to try to repro the issue on Safari on OSX and the same issue happened, which led me to the issue of enabling pop-ups in the Preferences menu within Safari, and then it worked!!! – Farooq Nov 19 '15 at 02:22

1 Answers1

1

Without details of the actual test failure and the JS that is bound to the click it's impossible to be 100% sure what issue you're having. The fact that #click is returning nil does not mean the link/div has not been clicked on. In this case it's more likely it has been clicked on but the JS that is supposed to be handling the click isn't doing what you expect, because Safari in iOS blocks popup windows from being initiated by anything but real user clicks - see javascript window.open in safari

You can confirm this is the case by just having the click handler do something different (alert, change the color of an element, etc) and confirm it is actually being called

Community
  • 1
  • 1
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • Thanks for the help Tom, you put me on the path to solve this issue! – Farooq Nov 19 '15 at 02:19
  • I'll accept this is as the official answer, but for those with the same issue, here's how to solve it: Go to the Preferences menu in Safari, under the Security tab, uncheck "Block pop-up windows" and that'll solve the issue :) – Farooq Nov 19 '15 at 02:28