CTLearn
CTLearn

Reputation: 115

How to enter information in a combo box with look up using Selenium webdriver?

I am having trouble with automating data entry in a combo-box with lookup/auto filling option element. The automation task is filtering data based on a company's name.

    driver.findElement(By.xpath(".//*[@id='s2id_company_id']")).click(); 
    driver.findElement(By.xpath(".//*[@id='s2id_company_id']")).sendKeys(companyname);
    ((WebElement) driver).sendKeys(Keys.ENTER); 

The script runs perfectly up until entering the data.

Stopping Point

Relevant HTML:

<div id="div_ff_company_id" class="ff_item filter-field" data-type="filter-field" condition="company_id" operator="is_in" container="multi_select" type="default" data-label="Customer">

<label class="control-label">Customer</label>

    <div class="select2-container select2-container-multi input-xlarge filter_item" id="s2id_company_id" style="width:100%"><ul class="select2-choices">  <li class="select2-search-field">    <label for="s2id_autogen79" class="select2-offscreen"></label>    <input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="select2-input" id="s2id_autogen79" placeholder="" style="width: 10px;">  </li></ul></div><input type="hidden" id="company_id" style="width:100%" class="input-xlarge filter_item select2-offscreen" tabindex="-1" value="">

Can you guys tell me if there is something I am overlooking?

Upvotes: 1

Views: 780

Answers (1)

Rakesh babu
Rakesh babu

Reputation: 56

After clicking on it ... I mean after driver.findElement(By.xpath(".//*[@id='s2id_company_id']")).click(); statement then use

WebElement currentElement = driver.switchTo().activeElement()// which give the active or currently focused element.

Try #1 : currentElement.sendKeys(companyname);

Try #2 : inspect the element in Dom then use sendkeys

Try #3 : use executeScript() which takes function calls and raw JS, too. You can return a value from it and you can pass lots of complicated arguments to it.

For reference http://www.seleniumhq.org/docs/03_webdriver.jsp#using-javascript

Hope it helps

Upvotes: 3

Related Questions