【发布时间】:2017-10-06 11:29:14
【问题描述】:
我正在尝试编写一个自动化测试,要求浏览器从日期选择器中选择今天的日期,但我无法解决或找到有关如何执行此操作的任何信息。我只能找到信息要求它选择一个指定的日期。但我希望我的测试选择它自己运行时恰好是“今天”的任何日期。
到目前为止我的代码...
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using FluentAssertions;
using System;
namespace UnitTestProject5
{
[TestClass]
public class Portal
{
[TestMethod]
public void TestMethod1()
{
IWebDriver Driver = new ChromeDriver();
// Logging in and other tests are here
// Setting the COT Date (CotDate field location set earlier. The date picker appears when you click the CotDate field)
CotDate.Click();
var DatePicker = Driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_wizDetails_chk_cot"));
//Close and Quit Chrome
Driver.Close();
Driver.Quit();
}
}
}
如果答案在其他地方,我将非常感谢它的链接 :) 从我目前看到的情况来看,看起来我可能需要使用 JavaScript?
谢谢,
谢里登
【问题讨论】:
-
I can only find information to ask it to select a specified date.这不是你想要做的吗?其中指定日期是DateTime.Today? -
你可以试试这个
string date = DatePicker.GetAttribute("value");并告诉我 -
@mjwills 是的。不久前,我使用“DateTime.Today”尝试了一些操作,但不知道该怎么做。测试一直失败。
-
@NarendraR - 添加的测试通过,但没有点击今天的日期。
-
你能告诉我们网址,以便我们帮助你
标签: c# visual-studio selenium datepicker automated-tests