Caleb Caleb - 23 days ago 14
Javascript Question

Cannot select hidden element in drop down list in Protractor

In my website I have a drop down list containing 50 data in the list. So, I'm going to write Protractor test script for read the final value in the list.

I've tried following code segment for drop down list.

element.all(by.model('salary_generate.company_id')).each(function (eachElement, index)
{
eachElement.click();
browser.driver.sleep(2000);
element(by.value('ESOFT Technologies (Pvt) Ltd.')).click();
browser.driver.sleep(2000);
});


This test fails.

Answer

Use following code. :)

// Create instance of Javascript executor
JavascriptExecutor je = (JavascriptExecutor) driver;
//Identify the WebElement which will appear after scrolling down
WebElement element = driver.findElement(By.tagName("...."));
// now execute query which actually will scroll until that element is not appeared on page.
je.executeScript("arguments[0].scrollIntoView(true);",element);