SetInputAction extends FindElementAction { @Override protected void execute(WebElement webElement, SeleniumBrowser browser, TestContext context) { super.execute(webElement, browser, context); String tagName = webElement.getTagName(); if (null == tagName || !"select".equals(tagName.toLowerCase())) { webElement.clear(); webElement.sendKeys(context.replaceDynamicContentInString(value)); } else { new Select(webElement).selectByValue(context.replaceDynamicContentInString(value)); } } SetInputAction(Builder builder); String getValue();  }
@Test public void testExecute() throws Exception { when(webDriver.findElement(any(By.class))).thenReturn(element); SetInputAction action = new SetInputAction.Builder() .browser(seleniumBrowser) .element("name", "textField") .value("new_value") .build(); action.execute(context); verify(element).clear(); verify(element).sendKeys("new_value"); }
@Test public void testExecuteOnSelect() throws Exception { WebElement option = Mockito.mock(WebElement.class); when(webDriver.findElement(any(By.class))).thenReturn(element); when(element.getTagName()).thenReturn("select"); when(element.findElements(any(By.class))).thenReturn(Collections.singletonList(option)); when(option.isSelected()).thenReturn(false); SetInputAction action = new SetInputAction.Builder() .browser(seleniumBrowser) .element("name", "textField") .value("option") .build(); action.execute(context); verify(option).click(); }