![](/img/trans.png)
[英]In Visual C#, how do I select data from an access table from a column titled with today's date
[英]Select today's date from a date picker - Selenium, C#, Visual Studio
我正在嘗試編寫一個自動測試,要求瀏覽器從日期選擇器中選擇今天的日期,但是我無法解決該問題,也找不到任何有關如何執行此操作的信息。 我只能找到要求其選擇指定日期的信息。 但是我希望我的測試選擇“今天”獨立運行的日期。
到目前為止,我的代碼...
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?
謝謝,
謝里登
我不得不與日期選擇器一起使用FindElementByLinkText()幾次。 獲取您要查找的日期的DateTime對象,並拆分所需的值(在本例中為Day int屬性),然后轉換為字符串。 使用該值作為FindElementByLinkText()中的參數。
var today = DateTime.Today;
var driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://seleniumpractise.blogspot.in/2016/08/how-to-handle-calendar-in-selenium.html");
driver.FindElementById("datepicker").Click();
driver.FindElementByLinkText(today.Day.ToString()).Click();
driver.Quit();
您可以使用此功能並將其傳遞給定位器
DateTime.Now.ToString("M/d/yyyy");
結果:“ 10/7/2017”
DateTime.Now.ToString("M-d-yyyy");
結果:“ 10-7-2017”
DateTime.Now.ToString("yyyy-MM-dd");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.