-1

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.

enter image description here

2
  • Please provide your source code as text. This will allow us to help you. Commented Sep 21, 2017 at 7:22
  • problem solved? Commented Sep 21, 2017 at 8:57

1 Answer 1

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");
Sign up to request clarification or add additional context in comments.

4 Comments

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

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.