0

Trying to send/set text using webdriver sendkeys() function for text field

Here is the HTML

<table class="gridtable" cellspacing="0" __gwtcellbasedwidgetimpldispatchingfocus="true"    gwtcellbasedwidgetimpldispatchingblur="true" style="width: 100%;">
<thead>
<colgroup>
<tbody style="">
<tr class="GORM0XEDKD GORM0XEDME" onclick="">
   <td class="GORM0XEDJD GORM0XEDLD GORM0XEDMD GORM0XEDNE">
   <td class="GORM0XEDJD GORM0XEDLD GORM0XEDNE GORM0XEDGE">
       <div style="outline:none;" tabindex="0"></div>
   </td>
</tr>
</tbody>
<tbody style="display: none;">
<tfoot style="display: none;">
</table>

Xpath for the text field -
EmailTemplateEditorTemplateName=  By.xpath("//*[contains(@class,'GORM0XEDJD GORM0XEDLD  GORM0XEDNE GORM0XEDGE')]/div[1]");
  • Tried following options. But all are failing to send text to EmailTemplateEditorTemplateName text field

    1. driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName).sendKeys("yahooo");
    
    2. this.WaitForElement(DesignerLocators.EmailTemplateEditorTemplateName);
       WebElement tempname = driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
       JavascriptExecutor rightexecutor = (JavascriptExecutor)driver;
       rightexecutor.executeScript("arguments[0].setAttribute('value','yahoo')", tempname);
    
    3. WebElement Element=driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
      Actions builder = new Actions(driver);
      builder.moveToElement(Element).sendKeys("yahoo").build().perform();
    
    4. WebElement Element=driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
      Actions builder = new Actions(driver);
      builder.moveToElement(Element).click().sendKeys("yahoo").build().perform();
    
    5. WebElement Element=driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
      Actions builder = new Actions(driver);
      builder.moveToElement(Element).click(Element).sendKeys("yahoo").build().perform();
    
  • click() is working.

  • Interestingly getText() is working for the same text field using same xpath. String val=driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName).getText();
  • Only sendKeys() is not working. And not throwing any error.
  • Please help me to set/send text in my text field.
12
  • PLease share the error or exception you are getting Commented Nov 16, 2014 at 15:29
  • sendKeys() executing successfully but text is not setting in text field. So i am not getting any error or exception. Commented Nov 16, 2014 at 15:36
  • and in case of using native javascript? Commented Nov 16, 2014 at 15:37
  • Yes ..even with using javascript failing to set/send text in text field. Commented Nov 16, 2014 at 15:42
  • I don't see any input elements in your HTML. Looks like you are trying to send keys to a div element? Commented Nov 16, 2014 at 15:42

3 Answers 3

5

Have you tried this:

Since you said that Click works,

driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName).click();
driver.switchTo().activeElement().sendKeys("Text");

or trying with builder click and activeElement as below

builder.moveToElement(Element).click();
driver.switchTo().activeElement().sendKeys("Text");
Sign up to request clarification or add additional context in comments.

Comments

1

There is no direct option in Selenium/Webdriver to set the value in "div" tag.

You need to Set the attribute innerHTML using JavascriptExecutor as below:

   this.WaitForElement(DesignerLocators.EmailTemplateEditorTemplateName);
   WebElement tempname = driver.findElement(DesignerLocators.EmailTemplateEditorTemplateName);
   JavascriptExecutor rightexecutor = (JavascriptExecutor)driver;
   rightexecutor.executeScript("arguments[0].setAttribute('innerHTML','yahoo')", tempname);

Comments

0

Check and see that latest version on driver(chromeor firefox) is being used as per the browser version. Please do this basic verification first. This mostly resolves the issue.

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.