如何使用C#从ajax calendarextender中选择selenium Webdriver中的日期

时间:2015-03-31 12:59:48

标签: c# selenium selenium-webdriver

IWebElement date = driver.FindElement(By.Id("ctl00_masterContentPlaceHolder_ImgBtnModifiedStart"));
IList<IWebElement> row = date.FindElements(By.TagName("tr"));
IList<IWebElement> col = date.FindElements(By.TagName("td"));

for (IWebElement cell: col)
{
    if (cell.Equals("13"))
    {
        cell.FindElement(By.LinkText("13")).Click();
    }
}


Error Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement occured at for loop

2 个答案:

答案 0 :(得分:0)

您的问题在这里:

if (cell.Equals("13"))

您想要访问Text ...

IWebElement属性
if (cell.Text.Equals("13")) .....

答案 1 :(得分:0)

这段代码对我有用:)

IWebElement date = driver.FindElement(By.Id(&#34; ctl00_masterContentPlaceHolder_CalendarExtender3_daysBody&#34;));

        IList<IWebElement> row = date.FindElements(By.TagName("tr"));
        IList<IWebElement> col = date.FindElements(By.TagName("td"));

        foreach (IWebElement cell in col)
        {
            if (cell.Text.Equals("13"))  
            {
                cell.Click();
                break;
            }    
        }