[go: up one dir, main page]

0% found this document useful (0 votes)
20 views1 page

Code Calender

This Java program uses Selenium to automate the selection of a date from a calendar on a website. It navigates to the specified URL, clicks on the travel date input, and iterates through the calendar to find and select the date '21' in May. The code includes necessary imports and sets up the ChromeDriver for browser automation.

Uploaded by

SuprinAhluwalia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

Code Calender

This Java program uses Selenium to automate the selection of a date from a calendar on a website. It navigates to the specified URL, clicks on the travel date input, and iterates through the calendar to find and select the date '21' in May. The code includes necessary imports and sets up the ChromeDriver for browser automation.

Uploaded by

SuprinAhluwalia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class calendar {

public static void main(String[] args) {


// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver", "C://work//chromedriver.exe");
ChromeDriver driver=new ChromeDriver();
driver.get("https://www.path2usa.com/travel-companions");
//April 23
driver.findElementByXPath(".//*[@id='travel_date']").click();

while(!driver.findElement(By.cssSelector("[class='datepicker-days']
[class='datepicker-switch']")).getText().contains("May"))
{
driver.findElement(By.cssSelector("[class='datepicker-days']
th[class='next']")).click();
}

List<WebElement> dates= driver.findElements(By.className("day"));


//Grab common attribute//Put into list and iterate
int count=driver.findElements(By.className("day")).size();

for(int i=0;i<count;i++)
{
String text=driver.findElements(By.className("day")).get(i).getText();
if(text.equalsIgnoreCase("21"))
{
driver.findElements(By.className("day")).get(i).click();
break;
}

}
}

Fullscreen
Go to Previous lecture93. Solved example on calendar methods

You might also like