选择页面对象模型中的元素

时间:2018-06-07 13:22:33

标签: c# selenium-webdriver

我正在处理页面对象模型,我想在主页的下拉列表中选择" Art"(它的元素检查值为339)。

namespace TestFramework
{
public class HomePage
{
    static string Url = "http://www.trademe.co.nz";
    private static string PageTitle = "Buy online and sell with NZ's #1 auction & classifieds site | Trade Me";
    private static string CarSaleTitle = "Car auctions | Used Cars for sale in New Zealand | Trade Me";


    [FindsBy(How = How.XPath, Using = "/html/body/div[2]/div[2]/div[1]/div[2]/div/div[1]/div/div[4]/div/div/div/div/div/div[1]/ul/li[3]/a")]
    private IWebElement motorsLink;

    [FindsBy(How = How.Name, Using = "searchType")]
    private IWebElement search;

    public SelectElement getSelectOptions()
    {
        return new SelectElement (search);
    }

    public void SetOption(int value)
    {
        getSelectOptions().SelectByIndex(value);
    }

    public void SelectMotors()
    {
        WebDriverWait wait = new WebDriverWait(Browser.Driver2, new TimeSpan(0, 0, 5));
        wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("/html/body/div[2]/div[2]/div[1]/div[2]/div/div[1]/div/div[4]/div/div/div/div/div/div[1]/ul/li[3]/a")));

        motorsLink.Click();
    }

    public void Goto()
    {
        Browser.Goto(Url);
    }

    public void ChooseArt()
    {
        WebDriverWait wait = new WebDriverWait(Browser.Driver2, new TimeSpan(0, 0, 5));
        wait.Until(ExpectedConditions.ElementIsVisible(By.Name("searchType")));

        SetOption(339);

    }

}
}

情景:

  1. 转到http://www.trademe.co.nz

  2. 选择" Art"来自下拉列表。

  3. 然而,系统总是告诉我" OpenQA.Selenium.WebDriverTimeoutException:5秒后超时"。 所以我想知道我哪里出错了?

0 个答案:

没有答案