Skip to content

Instantly share code, notes, and snippets.

@muditlambda
Created June 30, 2020 15:18
£
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Drawing;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
namespace NUnitDemo
{
class NUnit_Demo
{
IWebDriver driver;
[Test]
public void cssDemo()
{
driver = new ChromeDriver();
driver.Url = "http://demos.dojotoolkit.org/dijit/tests/test_Menu.html";
IWebElement element = driver.FindElement(By.XPath("//select[@aria-label='select']"));
SelectElement select_elem = new SelectElement(element);
/* Sleep for 4 seconds after page is displayed */
System.Threading.Thread.Sleep(4000);
select_elem.SelectByText("on IE6");
/* List will contain details of all the options */
IList<IWebElement> avail_options = select_elem.AllSelectedOptions;
int ListSize = avail_options.Count;
System.Diagnostics.Debug.WriteLine("List size is " + ListSize);
for (int loop_var = 0; loop_var < ListSize; loop_var++)
{
String text_value = avail_options.ElementAt(loop_var).Text;
System.Diagnostics.Debug.WriteLine("Selected item is " + text_value);
}
}
driver.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment