C#Selenium日历单击不起作用,出现错误 [英] C# Selenium Calendar click does not work and I get an error

查看:82
本文介绍了C#Selenium日历单击不起作用,出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够通过单击第一个日历获得帮助,并且需要为下一个日历做同样的事情。因此,我需要在第二个日历的第一个日历nad上选择月份的第一天,我需要在下个月的最后一天单击。我创建的时间表是每两个月。

I was able to get helped by clicking on the first calendar and needed to do the same thing for the next calendar. SO i need to pick 1st day of the mon th on the first calendar nad for the 2nd calendar i need to click on the last day of next month. The schedule im creating is every two months.

第一个日历选择如下,并且有效;

THe first calendar pick is as follows and this works;

IWebElement FromCalendar = Chromedriver.FindElement(By.Id("ctl00_MainContent_dpStart_B-1")); //
        FromCalendar.Click();

        //Always Click the current 1st day of the month
        new WebDriverWait(Chromedriver, TimeSpan.FromSeconds(2)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//td[@class='dxeCalendarDay'][.='1']"))).Click();

第二个日历如下,并且不起作用,我还创建了一个变量,该变量包含在xpath但我收到超时错误,即使我将秒数更改为20或30秒,我仍然会遇到相同的错误。如果我将变量中的值硬编码,它仍然无法工作。

The second calendar is the following and does not work, i also created a variable that is included in the xpath but i get a timeout error and even if i change the seconds to 20 or 30 seconds i still get the same error. If i hard coded the value in the variable it still wouldnt work.

String LastDayofNextMonth = endOfLastDayNextMonth.ToString("dd");

        // 2nd Calendar
        Chromedriver.FindElement(By.Id("ctl00_MainContent_dpEnd_B-1Img")).Click(); ; //

        //Click next month because schedule should be every 2 months

        Chromedriver.FindElement(By.Id("ctl00_MainContent_dpEnd_DDD_C_NMCImg")).Click(); //


        //Always Click the last day of next month - so schedule is for every 2 months

        new WebDriverWait(Chromedriver, TimeSpan.FromSeconds(3)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//td[@class='dxeCalendarDay'][.='"+LastDayofNextMonth+"']"))).Click();

日历确实打开并转到下个月,但未单击该月的最后一天,我收到以下错误;

The calendar does open and goes to the next month but the last day of the month is not clicked and i get the following error;

OpenQA.Selenium.WebDriverTimeoutException:'3秒后超时'

OpenQA.Selenium.WebDriverTimeoutException: 'Timed out after 3 seconds'

I我不确定为什么第一个日历有效而第二个日历无效。

I am not sure why the first calendar works and the second doesnt.

预先感谢您。

推荐答案

我知道了。

日历有2天30,因此它选择了10月的30,应该是最后一个下个月的11月30日。

The Calendar had 2 day 30 therefore it was choosing the 30 of the month of October and should be the last day of next month which is Nov 30.

最终代码;

new WebDriverWait(Chromedriver, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("(//td[@class='dxeCalendarDay'][.='"+LastDayofNextMonth+"'])[2]"))).Click();

这篇关于C#Selenium日历单击不起作用,出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆