【发布时间】:2016-10-21 18:13:42
【问题描述】:
我正在尝试从弹出的日历中选择出发日期和返回日期,但发现很难为日期选择编写通用代码。我正在尝试编写一个方法,其中日期从 main 方法作为参数和方法传递将执行并单击日历弹出窗口并选择单击日期。我已经编写了代码直到找到月份,但之后我被困在日期路径中,请帮忙。
弹窗截图:
我使用的网站是点击这里https://www.yatra.com/
Here is my code:
package Website;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class PickDateCalender {
static WebDriver driver=new FirefoxDriver();;
public static void main(String[] args) throws InterruptedException {
driver.get("https://www.yatra.com/");
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
WebElement element=driver.findElement(By.className("dropdown-toggle"));
String ori="New Delhi, India (DEL)";
String dest="Bangalore, India (BLR)";
String DepartDte="23-October-2016";
String splitter[]=DepartDte.split("-");
String Departdate=splitter[0];
System.out.println("date"+" "+Departdate);
String Departmonth=splitter[1];
System.out.println("month"+" "+Departmonth);
String Departyear=splitter[2];
System.out.println("year"+" "+Departyear);
String returDte="";
;
selectDate(Departdate,Departmonth,Departyear);
}
public static void selectDate(String Depardate,String Departmonth,String Departyear ){
WebElement Depart=driver.findElement(By.id("BE_flight_depart_date"));
Depart.click();
List <WebElement> month =driver.findElements(By.xpath(".//*[@id='PegasusCal-0']//ul[@class='month-list']"));
for(int i=0;i<month.size();i++){
String monname=month.get(i).getText();
if(monname.contains(Departmonth)){
System.out.println("Match found"+" "+monname);
System.out.println("inside if");
month.get(i).click();
break;
}
driver.close();
}
}
}
【问题讨论】:
-
你可以解释一下你想要什么
-
好的,我会在检查后更新我的查询 plzz revertr。我已经更新了我的查询是否足够好??
-
你的代码怎么失败了?
-
1.它没有在if循环内的参数中选择传递的月份。
标签: java eclipse selenium calendar