Search code examples
pythondjangotwitter-bootstrapfunctional-testing

How do I test for a Bootstrap tour popover in Django?


I am trying to create a functional test in Django (using Selenium) to check for a popover in a page as soon as the page loads:

tool_tip = self.browser.find_element_by_css_selector('div.popover').text
page = self.browser.find_element_by_tag_name('body').text
self.assertIn(tool_tip, page)

I have tried finding the popover using the id, and xpath. However, I keep getting the same error:

TypeError: argument of type 'WebElement' is not iterable

Is there any way to test for a bootstrap tour popover?

This is the code for the boostrap tour:

var tour = new Tour();

tour.addSteps([
{
    element   : '#bio_panel_nav',
    title     : 'Biography'    ,
    content   : 'Tell us a bit about yourself.',
    placement : 'top'
},

{
    element   : '#net_panel_nav',
    title     : 'Networks',
    content   : 'Link all your relevant social networks. ',
    placement : "top"
}

]);

tour.init().start();

Solution

  • You should be able to use the is_displayed method like so:

    self.assertTrue(
        self.browser.find_element_by_css_selector('div.popover').is_displayed())
    

    This will check that it's actually visible. You might end up needing to use something that waits for it to be displayed since the JS that displays it may not have been executed by the time is_displayed is called.