Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

C# Selenium Calendar click does not work and I get an error

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();

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: 'Timed out after 3 seconds'

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

Thank you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I figured it out.

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.

Final code;

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...