1

I'm trying to click on a link in navbar to trigger modal for third party authentication, which I need to test. I have some help before about how to fetch and click with selenium, and everything was good until this. This is the link I'm trying to click

<li class="pull-right hidden-xs hidden-sm" id="showlogin"><a href="#"><button type="button" class="btn btn-sm btn-info round">GET STARTED</button></a></li>

my test structure is:

def test_live_societe_login_using_third_party_modal(self):
    """TODO: Docstring for test_live_societe_login_third_party_modal.
    :returns: return modal for third party authentication

    """
    WebDriverWait(self.browser, 10).until(lambda browser:
                                          self.browser.find_element_by_id
                                          ('showlogin')).click()
    self.assertIn('http://societe.herokuapp.com/contact', self.browser.current_url)

I was able to test all application pages, but hitting this one I got selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with exception. I'm a little confused about it, can someone help me over come this, thanks.

copser
  • 2,523
  • 5
  • 38
  • 73
  • Selenium do not allow you to click on a hidden element. You can use javascript to make a click action as this question does: http://stackoverflow.com/questions/12040615/selenium-webdriver-clicking-on-hidden-element – Toan Nguyen Apr 14 '16 at 06:21
  • sorry for the late response, I think I know what is wrong, will answer later, nevertheless thanks. – copser Apr 14 '16 at 18:33

1 Answers1

0

Ok, I was locking at this the wrong way, in my navbar I have constructed GET STARTED button like this:

<li class="pull-right hidden-xs hidden-sm" id="showlogin"><a href="#"><button type="button" class="btn btn-sm btn-info round">GET STARTED</button></a></li>
<li class="dropdown hidden-md hidden-lg" id="showlogin">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="false" aria-expanded="false"><button type="button" class="btn btn-sm btn-info round">GET STARTED</button></a>
         <ul class="dropdown-menu">
             <li class="btn-group-vertical"><a id="facebook_login" href="/accounts/facebook/login" method="js-sdk" class="btn btn-default navbar-btn"><i class="fa fa-facebook"></i>&nbsp;Sign in with Facebook</a>
                 <a id="linkedin_login" href="/accounts/linkedin/login" class="btn btn-default navbar-btn"><i class="fa fa-linkedin"></i>&nbsp;Sign in with LinkedIn</a>
                 <a id="twitter_login" href="/accounts/twitter/login" class="btn btn-default navbar-btn"><i class="fa fa-twitter"></i>&nbsp;Sign in with Twitter</a></li>
                </ul>
            </li>

You can see that I have two <li></li> tags, one is a button for larger viewport and the other tag have dropdown menu for smaller viewport. In the first place I was not selecting the right <li></li> tag. When selenium start testing he opened a tablet view browser (≥768px) and that changed the situation in the sense of I needed to select dropdown and then find a button to click and trigger third party authentication.

I can select dropdown with Css selector, so I just find_element_by_css_selector('div#navbar ul li.dropdown'), after this I selected right social button. All I need to do now is handle social authentication.

This is the code for selecting dropdown and social button for third party authentication:

def test_live_societe_login_using_third_party_modal(self):
    """TODO: Docstring for test_live_societe_login_third_party_modal.
    :returns: return modal for third party authentication

    """
    dropSelect = WebDriverWait(self.browser, 20).until(
        lambda browser: (self.browser.find_element_by_css_selector('div#navbar ul li.dropdown')))
    dropSelect.click()
    twitter_choice = dropSelect.find_element_by_id('twitter_login')
    twitter_choice.click()
copser
  • 2,523
  • 5
  • 38
  • 73