選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

NativeSelectElement.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.WebElement;
  19. import org.openqa.selenium.support.ui.Select;
  20. import com.vaadin.testbench.By;
  21. import com.vaadin.testbench.TestBenchElement;
  22. import com.vaadin.testbench.elementsbase.ServerClass;
  23. @ServerClass("com.vaadin.ui.NativeSelect")
  24. public class NativeSelectElement extends AbstractSelectElement {
  25. private Select select;
  26. private WebElement selectElement;
  27. @Override
  28. protected void init() {
  29. super.init();
  30. selectElement = findElement(By.tagName("select"));
  31. select = new Select(selectElement);
  32. }
  33. /**
  34. * Gets the {@code <select>} element inside the component.
  35. *
  36. * @return the select element inside the component
  37. * @since
  38. */
  39. public WebElement getSelectElement() {
  40. return selectElement;
  41. }
  42. public List<TestBenchElement> getOptions() {
  43. return wrapElements(select.getOptions(), getCommandExecutor());
  44. }
  45. public void selectByText(String text) throws ReadOnlyException {
  46. if (isReadOnly()) {
  47. throw new ReadOnlyException();
  48. }
  49. select.selectByVisibleText(text);
  50. waitForVaadin();
  51. }
  52. /**
  53. * Clear operation is not supported for Native Select. This operation has no
  54. * effect on Native Select element.
  55. */
  56. @Override
  57. public void clear() {
  58. super.clear();
  59. }
  60. /**
  61. * Return value of the selected item in the native select element.
  62. *
  63. * @return value of the selected item in the native select element
  64. */
  65. public String getValue() {
  66. return select.getFirstSelectedOption().getText();
  67. }
  68. /**
  69. * Select item of the native select element with the specified value.
  70. *
  71. * @param chars
  72. * value of the native select item will be selected
  73. */
  74. public void setValue(CharSequence chars) throws ReadOnlyException {
  75. selectByText((String) chars);
  76. }
  77. }