You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NativeSelectElement.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.testbench.elements;
  17. import java.util.List;
  18. import org.openqa.selenium.support.ui.Select;
  19. import com.vaadin.testbench.By;
  20. import com.vaadin.testbench.TestBenchElement;
  21. import com.vaadin.testbench.elementsbase.ServerClass;
  22. @ServerClass("com.vaadin.ui.NativeSelect")
  23. public class NativeSelectElement extends AbstractSelectElement {
  24. private Select selectElement;
  25. @Override
  26. protected void init() {
  27. super.init();
  28. selectElement = new Select(findElement(By.tagName("select")));
  29. }
  30. public List<TestBenchElement> getOptions() {
  31. return wrapElements(selectElement.getOptions(), getCommandExecutor());
  32. }
  33. public void selectByText(String text) throws ReadOnlyException {
  34. if (isReadOnly()) {
  35. throw new ReadOnlyException();
  36. }
  37. selectElement.selectByVisibleText(text);
  38. waitForVaadin();
  39. }
  40. /**
  41. * Clear operation is not supported for Native Select. This operation has no
  42. * effect on Native Select element.
  43. */
  44. @Override
  45. public void clear() {
  46. super.clear();
  47. }
  48. /**
  49. * Return value of the selected item in the native select element
  50. *
  51. * @return value of the selected item in the native select element
  52. */
  53. public String getValue() {
  54. return selectElement.getFirstSelectedOption().getText();
  55. }
  56. /**
  57. * Select item of the native select element with the specified value
  58. *
  59. * @param chars
  60. * value of the native select item will be selected
  61. */
  62. public void setValue(CharSequence chars) throws ReadOnlyException {
  63. selectByText((String) chars);
  64. }
  65. }