001/*
002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Anahide Tchertchian
018 */
019package org.nuxeo.functionaltests.forms;
020
021import java.util.List;
022
023import org.openqa.selenium.By;
024import org.openqa.selenium.WebDriver;
025import org.openqa.selenium.WebElement;
026
027/**
028 * Element representing a select one radio directory widget.
029 *
030 * @since 7.4
031 */
032public class SelectOneRadioDirectoryWidgetElement extends WidgetElement {
033
034    public SelectOneRadioDirectoryWidgetElement(WebDriver driver, String id) {
035        super(driver, id);
036    }
037
038    /**
039     * Value should be the id of the option to select
040     */
041    @Override
042    public void setInput(WebElement elt, String value) {
043        List<WebElement> options = getInputElement().findElements(By.xpath(".//input[@type='radio']"));
044        for (WebElement option : options) {
045            if (option.getAttribute("value").equals(value)) {
046                option.click();
047                break;
048            }
049        }
050    }
051
052    public String getInputValue() {
053        List<WebElement> options = getInputElement().findElements(By.xpath(".//input[type='radio']"));
054        for (WebElement option : options) {
055            if (option.isSelected()) {
056                return option.getAttribute("value");
057            }
058        }
059        return "";
060    }
061
062    @Override
063    public WebElement getOutputElement() {
064        throw new UnsupportedOperationException("Output element cannot be retrived by id");
065    }
066
067}