I am using selenium webdriver and trying to automate a text field(Contact Email) which is hidden on the page initially. But when I select a value in the field (Case SubType), Contact Email text box and other fields get appeared on the page and I need to enter the value in my text box Contact Email here. I tried using javascript but it's not working. Please refer the snapshot for getting the clear picture.
Asked
Active
Viewed 374 times
-1
-
Please provide your **source code as text**. This will allow us to help you. – Noel Widmer Sep 21 '17 at 07:22
-
problem solved? – iamsankalp89 Sep 21 '17 at 08:57
1 Answers
0
Try this as example as you are not share anything:
First change the hidden value as text:
WebDriver Fdriver=new FirefoxDriver();
JavascriptExecutor js = (JavascriptExecutor)Fdriver;
//change the hidden value as text
js.executeScript("document.getElementsByName('body')[0].setAttribute('type', 'text');");
//locate element
driver.findElement("locator value).sendKeys("abcde");

iamsankalp89
- 4,607
- 2
- 15
- 36
-
Do I need to change anything in this line: //change the hidden value as text js.executeScript("document.getElementsByName('body')[0].setAttribute('type', 'text');"); – Namrata Sinha Sep 21 '17 at 10:11
-
-
Try this link, it helps me too https://stackoverflow.com/questions/11858366/how-to-type-some-text-in-hidden-field-in-selenium-webdriver-using-java – iamsankalp89 Sep 21 '17 at 10:19
-
Thanks it helped me... below is the code that worked for me perfectly: Thread.sleep(2000); WebElement contactemail = driver.findElement(By.xpath("locator value")); JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("arguments[0].setAttribute('type', 'text');", contactemail); contactemail.sendKeys("abc"); – Namrata Sinha Sep 21 '17 at 11:29