I am trying to select an item from a drop down list. I have put the code in the section below. My research has not been conclusive though:
- https://stackoverflow.com/questions/5278281/how-to-select-an-option-from-drop-down-using-selenium-webdriver-c
- https://stackoverflow.com/questions/5471515/select-a-value-from-drop-down-using-selenium-webdriver-c-sharp
- https://stackoverflow.com/questions/15535069/select-each-option-in-a-drop-down-using-selenium-webdriver-c-sharp
Here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
using System.Globalization;
using System.Threading.Tasks;
namespace CV_Lib_Do_Not_Use
{
class Program
{
static void Main(string[] args)
{
//Instantiate Firefox Driver
//Go to CV Library Website
var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("https://www.cv-library.co.uk/");
//Wait for web element to become visible
System.Threading.Thread.Sleep(15000);
//Click on Search Jobs tab
driver.FindElement(By.Id("header-link-searchjobs")).Click();
//Use the 'Keywords / Job Title / Job Ref' search field to search for a Test Analyst position
var position = driver.FindElement(By.XPath(".//*[@id='searchjobs_form']/div[1]/div[1]/input"));
//Type Test Analyst in the search box
position.SendKeys("Test Analyst");
//Use the 'Keywords / Job Title / Job Ref' search field to search for a Test Analyst position
var location = driver.FindElement(By.XPath(".//*[@id='location']"));
//Type Manchester in the search box
location.SendKeys("Manchester");
//Identify xpath for distance from desired location
var distance = driver.FindElement(By.XPath(".//*[@id='distance_adv']"));
//Click on 10 miles from the drop-down
driver.FindElement(By.XPath(".//*[@id='distance_adv']/option[6]")).Click();
}
}
}