001/*
002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Anahide Tchertchian
016 */
017package org.nuxeo.functionaltests.forms;
018
019import java.util.List;
020
021import org.openqa.selenium.By;
022import org.openqa.selenium.WebDriver;
023import org.openqa.selenium.WebElement;
024
025/**
026 * Element representing a select one radio directory widget.
027 *
028 * @since 7.4
029 */
030public class SelectOneRadioDirectoryWidgetElement extends WidgetElement {
031
032    public SelectOneRadioDirectoryWidgetElement(WebDriver driver, String id) {
033        super(driver, id);
034    }
035
036    /**
037     * Value should be the id of the option to select
038     */
039    @Override
040    public void setInput(WebElement elt, String value) {
041        List<WebElement> options = getInputElement().findElements(By.xpath(".//input[@type='radio']"));
042        for (WebElement option : options) {
043            if (option.getAttribute("value").equals(value)) {
044                option.click();
045            }
046        }
047    }
048
049    public String getInputValue() {
050        List<WebElement> options = getInputElement().findElements(By.xpath(".//input[type='radio']"));
051        for (WebElement option : options) {
052            if (option.isSelected()) {
053                return option.getAttribute("value");
054            }
055        }
056        return "";
057    }
058
059    @Override
060    public WebElement getOutputElement() {
061        throw new UnsupportedOperationException("Output element cannot be retrived by id");
062    }
063
064}