0

First Stack post, so don't be harsh if I get it wrong.

Im using selenium and java for some automated testing. All was going well until I tried to set the value of a hidden input.

When using 'type' in the Firefox IDE, it works a treat, but when I use the line below, it doesn't play at all. It just fails.

// This line doesnt like to run because its hidden
selenium.type("name=startDate_submit", "2015-09-25");

Can anyone point me in the right direction.

Many Thanks.

Edit:

WebDriver driver = new ChromeDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("$([name=startDate_submit]).attr('type', 'text');");
Thread.sleep(3000);
// This line doesnt like to run because its hidden
selenium.type("name=startDate_submit", "2015-09-25");

Should this be the way I do this? I just cannot get it working.

  • Possible duplicate http://stackoverflow.com/questions/11858366/how-to-type-some-text-in-hidden-field-in-selenium-webdriver-using-java – webNeat Aug 26 '14 at 15:09
  • Modified my code to user the snippet from the suggested dupe but to no avail. ` ... selenium.select("name=days[1][endtime][hours]", "label=15"); WebDriver driver = new ChromeDriver(); JavascriptExecutor jse = (JavascriptExecutor)driver; // Crashes on this line. and looks like it opens a new window, not the current one jse.executeScript("document.getElementsByName('startDate_submit')[0].setAttribute('type', 'text');"); Thread.sleep(3000); // This line doesnt like to run because its hidden selenium.type("name=startDate_submit", "2015-09-25");` – Martin McInnes Aug 26 '14 at 15:28
  • Apologies for the horrible formatting – Martin McInnes Aug 26 '14 at 15:30

2 Answers2

2

just try with this command,

driver.findElement(By.xpath("path")).sendKeys("value");

but make sure you have clicked that path before providing input value. come back if you still have any problem.

sibi
  • 174
  • 2
  • 9
0

Try with available javascript commads like document.getElementById, then set the value.