Resourceful Resourceful -4 years ago 186
C# Question

Selenium selecting a dropdown option using webdriver in c#

I am trying to click on a dropdown option selection and filter results. However, I cant seem to nail the syntax.

URL = ""

Dropdown selection for Location : 'Palo Alto'

My attempt is below:



It says that the element doesnt exist but I cant figure out the syntax.

What do I seem to be doing wrong?

Answer Source
  1. The dropdown and button elements are in iframe name "preview-frame". You have to switch to the iframe before finding the elements.
  2. You have to click the dropdown then select item inside the list

Code below show how to find dropdown and list elements from the label Location.

IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
jse.ExecuteScript("window.scrollBy(0,400)", "");
driver.FindElement(By.XPath("//label[contains(.,'Location')]/../div/div/ul/li/a[contains(.,'Palo Alto')]")).Click();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download