0

Now in the application that i have to automate, there's a jhtml Area element. This is a sample jhtml area: http://pietschsoft.com/demo/jhtmlarea/.

So the jhtml area has two elements for the text you enter. I have tried entering text using the text area tag. But doesn't work out. Any ideas? enter image description here

1
  • Can you please past in your code here... We can't help you from scratch... We can identify the problem from the code.. Mar 26, 2017 at 17:19

2 Answers 2

0

As per given sample URL, if you observe the HTML of JHTML it inside the iframe, so to enter the text inside you have to first switch to the iframe and than enter the text. Your code may look like below.

WebElement iframe = driver.findElement(By.xpath("//iframe")); // xpath of the iframe
driver.switchTo(iframe);

// Now enter the text in text area.
driver.findElement(By.xpath("//body")).sendKeys("Whatever text you want to send");
3
  • Unfortunately that doesn't work. If you see the image, the iframe has the <body> tag. But the text area, which has the text, is outside of it.
    – Swastik
    Mar 24, 2017 at 10:20
  • If you inspect the JHTML and edit text under body tag it will reflect the text in JHTML, but if you edit the textarea and enter the text there it does not reflect in JHTML. So you will have send the text inside the body tag. Mar 24, 2017 at 11:25
  • Sending to the body using sendkeys doesn't take the change. Even tried highlighting the body and using some action keys by simulating keyboard events. No luck.
    – Swastik
    Mar 24, 2017 at 13:02
0

As per your example URL, please try the following code in order to switch to the iframe for the jHTMLArea and manipulate the body text. The code is relatively straight forward, prepping the driver, navigate to the page, switching to the iframe and then manipulating the body, asserting the change and quitting the driver instance.

@Test
public void jarea() {
    String test = "Hello";
    System.setProperty("webdriver.chrome.driver", "C:/Automation/Chromedriver.exe");
    WebDriver d = new ChromeDriver();


    d.navigate().to("http://pietschsoft.com/demo/jhtmlarea/");  


    WebElement iframe = d.findElement(By.xpath("//iframe")); 
    d.switchTo().frame(iframe);

    WebElement jAreaBody = d.findElement(By.xpath("/html/body"));
    jAreaBody.clear();
    jAreaBody.sendKeys(test);
    assertEquals(jAreaBody.getText(), test);
    d.quit();

}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.