Selenium + C# - 在另一种方法中重用一个方法

时间:2015-01-13 16:30:44

标签: c# selenium-webdriver nunit extension-methods

目前我有以下代码:

 [Test]
    public void b_AcessarNovaVenda()
    {
        driver.FindElement(By.XPath("//*[@href='/Vendas']")).Click();

        WebDriverWait esperaMenu = new WebDriverWait(driver, TimeSpan.FromSeconds(3));
        esperaMenu.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@href='/Vendas/Nova-Venda']")));

        driver.FindElement(By.XPath("//*[@href='/Vendas/Nova-Venda']")).Click();

        System.Threading.Thread.Sleep(2000);
    }

    [Test]
    public void c_EfetuarPesquisaVoosSomenteIda()
    {
        driver.SwitchTo().Frame(driver.FindElement(By.XPath("/html/body/form/div[6]/div/div[2]/iframe")));

        driver.FindElement(By.CssSelector(".voos")).Click();

        driver.FindElement(By.Id("rbtOnlyWay")).Click();

        driver.FindElement(By.Id("p_lt_ctl05_pageplaceholder_p_lt_ctl02_FSXBuscador_txtDeparture_txtDescription")).SendKeys("bage");

        WebDriverWait esperaAutoPreenchimentoOrigem = new WebDriverWait(driver, TimeSpan.FromSeconds(3));
        esperaAutoPreenchimentoOrigem.Until(ExpectedConditions.ElementIsVisible(By.ClassName("ac_results")));

        driver.FindElement(By.ClassName("ac_even")).Click();

        driver.FindElement(By.Id("p_lt_ctl05_pageplaceholder_p_lt_ctl02_FSXBuscador_txtArrival_txtDescription")).SendKeys("miami");

        WebDriverWait esperaAutoPreenchimentoDestino = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
        esperaAutoPreenchimentoDestino.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@class='ac_even ac_over']")));

        driver.FindElement(By.XPath("//*[@class='ac_even ac_over']")).Click();

        driver.FindElement(By.Id("p_lt_ctl05_pageplaceholder_p_lt_ctl02_FSXBuscador_txtDepartureDateAero")).Click();

        for (int i = 0; i < IncrementMonth; i++)
        {
            driver.FindElement(By.CssSelector("span.ui-icon.ui-icon-circle-triangle-e")).Click();
        }

        driver.FindElement(By.XPath("//a[contains(text(),'1')]")).Click();
        System.Threading.Thread.Sleep(1000);
        driver.FindElement(By.Id("btnSearchFSX")).Click();
    }

    [Test]
    public void d_RetornaResultados()
    {
        System.Threading.Thread.Sleep(10000);

        try
        {
            driver.FindElement(By.ClassName("resultado-voos-item-reservar")).Click();
            //Console.WriteLine("apareceu");
        }
        catch (NoSuchElementException)
        {

            b_AcessarNovaVenda();
         }

我需要在访问 catch(NoSuchElementException)行的代码时再次运行方法 public void b_AcessarNovaVenda(),但我收到错误:

NoSuchElementException异常

我无法再次运行该方法。为什么呢?

干杯

0 个答案:

没有答案