mil.dod.th.ose.gui.integration/src/mil/dod/th/ose/gui/integration/helpers/GeneralHelper.java
public static void toggleAccordion(final WebElement accordion, final String panelText, final ExpandCollapse choice)
    {
        List<WebElement> accordionHeaders = accordion.findElements(By.tagName("h3"));
        
        final String desiredExpandedState = choice == ExpandCollapse.EXPAND ? "true" : "false";
        
        WebElement desiredHeader = null;
        for (final WebElement accordionHeader : accordionHeaders)
        {
            WebElement linkElement = safeFindElement(accordionHeader, By.cssSelector("a"));

            if (linkElement.getText().equals(panelText))
            {
                desiredHeader = accordionHeader;
                break;
            }
        }
        
        assertThat(desiredHeader, is(notNullValue()));
                
        if (!desiredHeader.getAttribute(EXPANDED_ATTR_KEY).equals(desiredExpandedState)) 
        {
            LOG.log(Level.INFO, "Clicked accordion link [{0}] to: {1}", new Object[] {panelText, choice});
            desiredHeader.findElement(By.cssSelector("a")).click();
        }
        
        safeWaitUntil(new ExpectedCondition<Boolean>()
        {
            @Override
            public Boolean apply(WebDriver arg0)
            {
                // find element again as the toggle can update the DOM
                List<WebElement> updatedHeaders = accordion.findElements(By.tagName("h3"));
                WebElement updatedHeader = null;
                for (final WebElement accordionHeader : updatedHeaders)
                {
                    WebElement linkElement = safeFindElement(accordionHeader, By.cssSelector("a"));

                    if (linkElement.getText().equals(panelText))
                    {
                        updatedHeader = accordionHeader;
                        break;
                    }
                }
                
                String actualExpandedState = updatedHeader.getAttribute(EXPANDED_ATTR_KEY);
                LOG.log(Level.INFO, "Expecting accordion state of [{0}] and is [{1}]", 
                        new Object[] {desiredExpandedState, actualExpandedState});
                return actualExpandedState.equals(desiredExpandedState);
            }
        });
    }
/**
     * Toggle a given accordion element.
     * 
     * @param accordion
     *      accordion to toggle
     * @param panelText
     *      text of the panel that needs to be toggled
     * @param choice
     *      whether to expand or collapse panel
     */
Toggle a given accordion element.

@param accordion
accordion to toggle
@param panelText
text of the panel that needs to be toggled
@param choice
whether to expand or collapse panel
Toggle a given accordion element . @param accordion accordion to toggle @param panelText text of the panel that needs to be toggled @param choice whether to expand or collapse panel
public static void toggleAccordion(final WebElement accordion, final String panelText, final ExpandCollapse choice)
    {
        List<WebElement> accordionHeaders = accordion.findElements(By.tagName("h3"));
        final String desiredExpandedState = choice == ExpandCollapse.EXPAND ? "true" : "false";
        WebElement desiredHeader = null;
        for (final WebElement accordionHeader : accordionHeaders)
        {
            WebElement linkElement = safeFindElement(accordionHeader, By.cssSelector("a"));
            if (linkElement.getText().equals(panelText))
            {
                desiredHeader = accordionHeader;
                break;
            }
        }
        assertThat(desiredHeader, is(notNullValue()));
        if (!desiredHeader.getAttribute(EXPANDED_ATTR_KEY).equals(desiredExpandedState)) 
        {
            LOG.log(Level.INFO, "Clicked accordion link [{0}] to: {1}", new Object[] {panelText, choice});
            desiredHeader.findElement(By.cssSelector("a")).click();
        }
        safeWaitUntil(new ExpectedCondition<Boolean>()
        {
            @Override
            public Boolean apply(WebDriver arg0)
            {
                List<WebElement> updatedHeaders = accordion.findElements(By.tagName("h3"));
                WebElement updatedHeader = null;
                for (final WebElement accordionHeader : updatedHeaders)
                {
                    WebElement linkElement = safeFindElement(accordionHeader, By.cssSelector("a"));
                    if (linkElement.getText().equals(panelText))
                    {
                        updatedHeader = accordionHeader;
                        break;
                    }
                }
                String actualExpandedState = updatedHeader.getAttribute(EXPANDED_ATTR_KEY);
                LOG.log(Level.INFO, "Expecting accordion state of [{0}] and is [{1}]", 
                        new Object[] {desiredExpandedState, actualExpandedState});
                return actualExpandedState.equals(desiredExpandedState);
            }
        });
    }
public static void toggleAccordion ( final WebElement accordion , final String panelText , final ExpandCollapse choice ) { List < WebElement > accordionHeaders = accordion . findElements ( By . tagName ( "h3" ) ) ; final String desiredExpandedState = choice == ExpandCollapse . EXPAND ? "true" : "false" ; WebElement desiredHeader = null ; for ( final WebElement accordionHeader : accordionHeaders ) { WebElement linkElement = safeFindElement ( accordionHeader , By . cssSelector ( "a" ) ) ; if ( linkElement . getText ( ) . equals ( panelText ) ) { desiredHeader = accordionHeader ; break ; } } assertThat ( desiredHeader , is ( notNullValue ( ) ) ) ; if ( ! desiredHeader . getAttribute ( EXPANDED_ATTR_KEY ) . equals ( desiredExpandedState ) ) { LOG . log ( Level . INFO , "Clicked accordion link [{0}] to: {1}" , new Object [ ] { panelText , choice } ) ; desiredHeader . findElement ( By . cssSelector ( "a" ) ) . click ( ) ; } safeWaitUntil ( new ExpectedCondition < Boolean > ( ) { @ Override public Boolean apply ( WebDriver arg0 ) { List < WebElement > updatedHeaders = accordion . findElements ( By . tagName ( "h3" ) ) ; WebElement updatedHeader = null ; for ( final WebElement accordionHeader : updatedHeaders ) { WebElement linkElement = safeFindElement ( accordionHeader , By . cssSelector ( "a" ) ) ; if ( linkElement . getText ( ) . equals ( panelText ) ) { updatedHeader = accordionHeader ; break ; } } String actualExpandedState = updatedHeader . getAttribute ( EXPANDED_ATTR_KEY ) ; LOG . log ( Level . INFO , "Expecting accordion state of [{0}] and is [{1}]" , new Object [ ] { desiredExpandedState , actualExpandedState } ) ; return actualExpandedState . equals ( desiredExpandedState ) ; } } ) ; }
Toggle a given accordion element.
Toggle a given accordion element .
// find element again as the toggle can update the DOM