Code for clicking a day on calender does not execute | Selenium Forum
M
Posted on 25/12/2015
This code is suppose to click the day on the calender [i specify the day].

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Test {

public static void main(String[] args) {
// TODO Auto-generated method stub

//all columns n rows of webTable initiated
int count_rows=5;int count_cols=7;
int m=1;int col=0;String Day_s="29";String c=" " ;
int R=0;int n=1;

//xpath in parts
String p1="//*[@id='ui-datepicker-div']/div[2]/table/tbody/tr[";
String p2="]/td[";
String p3="]/*";
//getting the page of makemytrip website
WebElement v;
WebDriver w=new FirefoxDriver();
List <WebElement> z=new ArrayList <WebElement>();
w.get("http://www.makemytrip.com/flights");
w.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
w.findElement(By.xpath("//*[@id='start_date_sec']/span[2]")).click();

//row n col representation
for(m=1;m<=count_rows;m++)//Try m=5==========================>it works fine
{

for(n=1;n<=count_cols;n++)//Try n=3=========================>it works fine
{
System.out.println("C"+count_cols);
c=p1+m+p2+n+p3;
System.out.println("here xpath"+c);
v=w.findElement(By.xpath(c));//<==========Some issue here on debugging[Not sure what ======================
System.out.println("size"+v.getSize());
System.out.println("v.gettxet"+v.getText());

if(v.getText().matches(Day_s))

{
v.click();
break;
}

else
{
System.out.println("not match");
}


}
}



}
}

Note:
Issue is....for loop never crosses m=1,n=1.
Day_s=29 ,so:xpath=//*[@id='ui-datepicker-div']/div[2]/table/tbody/tr[5]/td[3]/a
If i specify m=5,n=3 ,it selects the correct day from calander,other wise NO.
Can you please help me in running this 2 for loops appropriately...

M
Replied on 26/12/2015

have you tried using sendkeys()