选择带有Selenium的Datepicker。第一轮OK,第二轮就挂了

时间:2015-09-24 18:44:51

标签: c# selenium datepicker datepickerdialog

我正在成功设置日期选择器的日期...,是的,我要复制代码结构以设置第二个日期选择器的日期,那就是出现问题的时候。 我只是不知道为什么第二次尝试不起作用。例如,如果我评论第一个日期选择器的第一组,第二个工作正常...,或者如果我改变位置,第一个将是唯一一个工作... 有线索吗?这是代码..(dummyInner有select元素html) Error that is displayed

#region DATEFROM

// Open First Datepicker
driver.FindElement(By.Id("dateFrom")).SendKeys("");

#region Month From

var monthPicker = "//select[@class='ui-datepicker-month']";
var select = driver.FindElement(By.XPath(monthPicker), 1);

var selectMesDesde = new SelectElement(select);
selectMesDesde.SelectByValue((iFrom.Month - 1).ToString());

#endregion

#region Year From

var yearPicker = "//select[@class='ui-datepicker-year']";
select = driver.FindElement(By.XPath(yearPicker), 1);

var selectAñoDesde = new SelectElement(select);
selectAñoDesde.SelectByValue(iFrom.Year.ToString());

#endregion

var datumPath = "//table[@class='ui-datepicker-calendar']/tbody/tr/td/a[contains(text(), '" + iFrom.Day + "')]";
var datum = driver.FindElement(By.XPath(datumPath), 1);
datum.Click();
Thread.Sleep(2000);

#endregion

#region DATETO

// Open second datepicker
driver.FindElement(By.Id("dateTo")).SendKeys("");
Thread.Sleep(500);

#region Month To

monthPicker = "//div[@id='ui-datepicker-div']//div//div[@class='ui-datepicker-title']//select[1]";
            select = driver.FindElement(By.XPath(monthPicker), 1);

            var dummyInner = select.GetAttribute("outerHTML");

            try
            {
                var selectMesHasta = new SelectElement(select);
                selectMesHasta.SelectByValue((iTo.Month - 1).ToString());
            }
            catch (Exception ex)
            {
                LogHelper.Trace(TraceEventType.Information, "No se puso obtener la fuente HTML de los movimientos " + ex.Message);
                return "";
            }

#endregion

#region Year To

yearPicker = "//select[@class='ui-datepicker-year']";
select = driver.FindElement(By.XPath(yearPicker), 1);

var selectAñoHasta = new SelectElement(select);
selectAñoHasta.SelectByValue(iTo.Year.ToString());

#endregion

datumPath = "//table[@class='ui-datepicker-calendar']/tbody/tr/td/a[contains(text(), '" + iTo.Day + "')]";
datum = driver.FindElement(By.XPath(datumPath), 1);
datum.Click();
Thread.Sleep(2000);

#endregion

1 个答案:

答案 0 :(得分:0)

人,它只是在同事的计算机和其他计算机上工作,但不在我的电脑上。奇怪,真奇怪......,即使使用相同版本的Firefox和VS ......