Search in sources :

Example 16 with HtmlRadioButtonInput

use of com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput in project posters-advanced-loadtest-suite by Xceptance.

the class FormUtils method checkRadioButton.

public static HtmlRadioButtonInput checkRadioButton(final HtmlRadioButtonInput radioButton) {
    // Remove checked state from previously checked radio button
    final HtmlForm form = radioButton.getEnclosingForm();
    if (form != null) {
        final LookUpResult previouslyChecked = HPU.find().in(form).byCss("[name='" + radioButton.getNameAttribute() + "'][checked]");
        if (previouslyChecked.exists()) {
            final HtmlRadioButtonInput oldRadioButton = previouslyChecked.single();
            oldRadioButton.setChecked(false);
            oldRadioButton.removeAttribute("checked");
        }
    } else {
        // Comment the next line if you know what you're doing only.
        Assert.fail("RadioButton is NOT inside a form. This might be due to broken HTML. It's strongly recommended to fix HTML issues first, then continue testing.");
    }
    // Check current radio button
    radioButton.setChecked(true);
    radioButton.setAttribute("checked", "checked");
    if (isNotLoadTestMode) {
        XltLogger.runTimeLogger.info(String.format("Checking radio button: %s", getIdOrName(radioButton)));
    }
    return radioButton;
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlRadioButtonInput(com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput) LookUpResult(com.xceptance.loadtest.api.hpu.LookUpResult)

Aggregations

HtmlRadioButtonInput (com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput)16 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)11 Test (org.junit.Test)8 HtmlCheckBoxInput (com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput)6 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)4 HtmlButton (com.gargoylesoftware.htmlunit.html.HtmlButton)4 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)4 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)4 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)3 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)3 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)2 TextPage (com.gargoylesoftware.htmlunit.TextPage)2 StyleElement (com.gargoylesoftware.htmlunit.css.StyleElement)2 BaseFrameElement (com.gargoylesoftware.htmlunit.html.BaseFrameElement)2 HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)2 HtmlButtonInput (com.gargoylesoftware.htmlunit.html.HtmlButtonInput)2 HtmlTextArea (com.gargoylesoftware.htmlunit.html.HtmlTextArea)2 Element (com.gargoylesoftware.htmlunit.javascript.host.Element)2 HTMLBodyElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLBodyElement)2 HTMLCanvasElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCanvasElement)2