Using Selenium 2 IWebDriver to interact with elements on a page

I use Selenium IWebDriverto write Unit Tests in C #.

Here is an example:

IWebDriver defaultDriver = new InternetExplorerDriver();
var ddl = driver.FindElements(By.TagName("select"));

The last line retrieves the HTML element selectenclosed in IWebElement.

I need a way to simulate highlighting for a specific optionin this selectlist , but I cannot figure out how to do this.


After some research, I found examples where people use a class ISelenium DefaultSeleniumto do the following, but I do not use this class because I'm doing everything with IWebDriverand INavigation(from defaultDriver.Navigate()).

I also noticed that it ISelenium DefaultSeleniumcontains a ton of other methods that are not available in specific implementations IWebDriver.

IWebDriver INavigation ISelenium DefaultSelenium?

+5
2

ZloiAdun, OpenQA.Selenium.Support.UI Select. , api . , -, .

<!DOCTYPE html>
<head>
<title>Disposable Page</title>
</head>
    <body >
        <select id="select">
          <option value="volvo">Volvo</option>
          <option value="saab">Saab</option>
          <option value="mercedes">Mercedes</option>
          <option value="audi">Audi</option>
        </select>
    </body>
</html>

, . , Select, IWebElement. Select . , .

using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium;
using System.Collections.Generic;
using OpenQA.Selenium.IE;

namespace Selenium2
{
    class SelectExample
    {
        public static void Main(string[] args)
        {
            IWebDriver driver = new InternetExplorerDriver();
            driver.Navigate().GoToUrl("www.example.com");

            //note how here i'm passing in a normal IWebElement to the Select
            // constructor
            Select select = new Select(driver.FindElement(By.Id("select")));
            IList<IWebElement> options = select.GetOptions();
            foreach (IWebElement option in options)
            {
                System.Console.WriteLine(option.Text);
            }
            select.SelectByValue("audi");

            //This is only here so you have time to read the output and 
            System.Console.ReadLine();
            driver.Quit();

        }
    }
}

, . -, DLL . Java ( PageObject), .Net. , . SVN, WebDriver.Common.dll - # Express 2008. , Internet Explorer Firefox.

, . , , select

driver.FindElements(By.TagName("select"));

all. , , driver.FindElement, 's'.

, Inavigation . , driver.Navigate().GoToUrl("http://example.com");

, DefaultSelenium - Selenium 1.x apis. Selenium 2 - Selenium 1, , Selenium 2 api ( WebDriver api), DefaultSelenium.

+7

option select ddl.FindElements(By.TagName("option"));. SetSelected IWebElement

. , # select WebDriver - Java. , code,

+2

All Articles