How to handle calendar in Selenium Webdriver and web table
In my recent article I have handled web table and calendar multiple times and in this article, I will show you how you can handle calendar in Selenium Webdriver using table approach.
I will use JQuery Date picker for example and you can take any example because approach will remain same. I will be using findElements methods to find all the dates and then will get the text and will click on the respective date.
Below image is an example of Date picker which is JQuery widget
Approach to handle calendar in Selenium Webdriver
Step 1- Click on calendar
Step 2- Get all td of tables using findElements method
Step 3- using for loop get text of all elements
Step 4- using if else condition we will check specific date
Step 5- If date is matched then click and break the loop.
Program to handle calendar in Selenium Webdriver
I am using Selenium 3 in below post so in case you are completely new to Selenium 3 then check out the new firefox with Selenium 3.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package Blog;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class CalendarHandling {
public static void main(String[] args)
{
System.setProperty("webdriver.firefox.marionette","G:\\Selenium\\Firefox driver\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("http://seleniumpractise.blogspot.in/2016/08/how-to-handle-calendar-in-selenium.html");
driver.findElement(By.id("datepicker")).click();
List<WebElement> allDates=driver.findElements(By.xpath("//table[@class='ui-datepicker-calendar']//td"));
for(WebElement ele:allDates)
{
String date=ele.getText();
if(date.equalsIgnoreCase("28"))
{
ele.click();
break;
}
}
}
}
|
0 comments:
Post a Comment