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.

3
  • Possible duplicate stackoverflow.com/questions/11858366/… Commented Aug 26, 2014 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");` Commented Aug 26, 2014 at 15:28
  • Apologies for the horrible formatting Commented Aug 26, 2014 at 15:30

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

But it don't have the driver anywhere. I only have an instance of defaultselenium
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.