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.
1 Answer
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");
4 Comments
Namrata Sinha
Do I need to change anything in this line: //change the hidden value as text js.executeScript("document.getElementsByName('body')[0].setAttribute('type', 'text');");
iamsankalp89
Let me check first]
iamsankalp89
Try this link, it helps me too stackoverflow.com/questions/11858366/…
Namrata Sinha
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");