Last active
August 11, 2022 03:48
-
-
Save bharathmuddada/ff27da1759b420a16d1304da12b76a89 to your computer and use it in GitHub Desktop.
c# selenium program to handle calendars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SeleniumCalendarExample { | |
public static void Main(string[] args) | |
{ | |
new DriverManager().SetUpDriver(new EdgeConfig()); | |
var driver = new EdgeDriver(); | |
driver.Manage().Window.Maximize(); | |
driver.Navigate().GoToUrl("https://jqueryui.com/datepicker/#date-range"); | |
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); | |
var frame_element = driver.FindElement(By.XPath("//*[@id='content']/iframe")); | |
driver.SwitchTo().Frame(frame_element); | |
var from_element = driver.FindElement(By.XPath("//input[@id='from']")); | |
from_element.Click(); | |
var month_element = driver.FindElement(By.XPath("//select[@class='ui-datepicker-month']")); | |
var month_select = new SelectElement(month_element); | |
//var month = DateTime.Now.Month; | |
month_select.SelectByText("Aug"); | |
var Day = DateTime.Now.Day -1; | |
Console.WriteLine("Current Day : " + Day); | |
var date_element = driver.FindElement(By.XPath($"//table/tbody/tr/td/a[text()='{Day}']")); | |
date_element.Click(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment