0

I am trying to sendKeys to the fields in an inline popup. company_name, contact_surname and contact_first_name. There are no iframes. I tried windowhandler also, but that did not work. Here is my code snippet and Please find the HTML code below::

driver.findElement(By.xpath("//input[@name='company_name']")).sendKeys("Ginger Bread");
driver.findElement(By.name("contact_first_name")).sendKeys("Ingrid");
driver.findElement(By.name("contact_surname")).sendKeys("Cumberbridge");

HTML Code:

<div id="ibox_content" style="overflow: auto; height: 322px;"><div id="quickCreateForm" style="background:silver; padding:4px; border:1px solid white; width:95%;">
<form> 
    <table width="100%" border="0" cellpadding="2" cellspacing="0">
    <tbody><tr><td colspan="2" align="center">
    <input type="button" value="Create" class="button" onclick="return quickCreate(this, true); ">

    <input type="button" value="Close" class="button" onclick="iBox.hide();">

    </td></tr>
    <tr><td align="right" valign="top"><strong>Company:</strong></td>
        <td align="left" valign="top" nowrap="">  
        <input type="text" name="company_name" value="" size="15" maxlength="120">
    </td></tr>
    <tr><td align="right" valign="top"><strong>First Name:</strong></td>
        <td align="left" valign="top"> 
        <input type="text" name="contact_first_name" value="" size="15" maxlength="120">
    </td></tr> 
    <tr><td align="right" valign="top"><strong>Last Name:</strong></td>
        <td align="left" valign="top">
        <input type="text" name="contact_surname" value="" size="15" maxlength="120"> 
        </td></tr>

    </tbody></table>
</form>
</div></div>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
user1411
  • 11
  • 1
  • 9
  • Please have a read through how to provide a [mcve]. As the question stands, it is very difficult to answer. – SiKing Oct 09 '18 at 23:57

5 Answers5

1

Try using CSS Selector driver.findElement(By.CssSelector("input[name=company_name]")).sendKeys("Ginger Bread"); driver.findElement(By.CssSelector("input[name=contact_first_name]")).sendKeys("Ingrid"); driver.findElement(By.CssSelector("input[name=contact_surname]")).sendKeys("Cumberbridge");

0

The below xpath should help you:

//div[@id='ibox_content' and contains(@style,'height')]//input[@name="company_name"]

Kireeti Annamaraj
  • 1,037
  • 1
  • 8
  • 12
0

Try with the xpath given below:

driver.findElement(By.xpath("//input[contains(@name,'company_na')]")).sendKeys("Ginger Bread");
0

You can use the following Locator Strategies to invoke sendKeys() to the desired fields:

  • Company:

    driver.findElement(By.xpath("//div[@id='quickCreateForm']/form//td/strong[contains(.,'Company')]//following::td[1]/input")).sendKeys("Ginger Bread");
    
  • First Name:

    driver.findElement(By.xpath("//div[@id='quickCreateForm']/form//td/strong[contains(.,'First Name')]//following::td[1]/input")).sendKeys("Ingrid");
    
  • Last Name:

    driver.findElement(By.xpath("//div[@id='quickCreateForm']/form//td/strong[contains(.,'Last Name')]//following::td[1]/input")).sendKeys("Cumberbridge");
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

It seems you are sending keys before actual element is getting loaded, so You need to give explicit wait before you are trying to sendkeys to it,

WebElement element = new WebDriverWait(Driver,30).until(ExpectedConditions.elementToBeClickable(By.name("company_name")));

or you may use this,

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

then call,

driver.findElement(By.xpath("//input[contains(@name,'company_name')]")).sendKeys("Ginger Bread");
Ashish Kamble
  • 2,555
  • 3
  • 21
  • 29