JavaScript method to select the dropdown option

We can use the Javascript method to select an option from the dropdown with the help of JavaScriptExecutor. We have to set the dropdown option using the value property of the element.

1. Open the browser and navigate to URL
2. Find the dropdown
3. Set the value using Javascript executor

import { browser, element, by, ElementFinder} from 'protractor'
describe('Protractor Typescript Demo', function() {
	browser.ignoreSynchronization = true; // for non-angular websites
	it('Excel File Operations', function() {
		// set implicit time to 30 seconds
		browser.manage().timeouts().implicitlyWait(30000);

		browser.get("https://chercher.tech/practice/dropdowns")
		element(by.css("select#first")).then(function(element){
			browser.executeScript("arguments[0].value='Yahoo'", element);
		})
	});
});

Protractor Interview Questions

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions