Java 下拉列表中的选项不是webdriver读取
场景:比较旧月份和新月份,如果两者不相等,则下载新月份的报告 以下是网站链接: 它读取所有,并忽略所有选项读取2016年1月和下载报告,直接跳到11月,而不是下载12月报告。静态旧月我从一个txt文件,即:2015年10月采取 代码如下:Java 下拉列表中的选项不是webdriver读取,java,selenium-webdriver,Java,Selenium Webdriver,场景:比较旧月份和新月份,如果两者不相等,则下载新月份的报告 以下是网站链接: 它读取所有,并忽略所有选项读取2016年1月和下载报告,直接跳到11月,而不是下载12月报告。静态旧月我从一个txt文件,即:2015年10月采取 代码如下: WebElement selectElement = driver.findElement(By.id("ReportViewerControl_ctl04_ctl03_ddValue")); //Getting the count
WebElement selectElement = driver.findElement(By.id("ReportViewerControl_ctl04_ctl03_ddValue"));
//Getting the count of the values in the drop down list
Select listBox = new Select(selectElement);
int size1 = listBox.getOptions().size();
//prints the size to the console
System.out.println("Total no. of months in the drop down is:"+ size1);
System.out.println("The old month is: " + oldMonth);
//String newMonth ="";
//listBox.selectByIndex(3);
String newMonth ;
for (int i = 1; i < size1; i++) {
WebElement mSelectElement = driver.findElement(By.xpath(".//*[@id='ReportViewerControl_ctl04_ctl03_ddValue']"));
List<WebElement> optionsList = mSelectElement.findElements(By.tagName("option"));
WebElement element = optionsList.get(i);
newMonth = element.getText();
//Message that prints the new month
System.out.println("The new month is:"+newMonth);
/*Condition to check if the New month is equal to Old month, if it is not equal then proceeds
* to download that particular month data or else breaks the loop
*/
if (!oldMonth.equals("All") & !newMonth.equals("All")) {
if (oldMonth.equals(newMonth)) {
System.out.println("No new months are available to download");
Wait(10000);
driver.close();
break;
}//else if (i==1 || (oldMonth.equals(newMonth))) {
//else if (i==1 & !(oldMonth.equals(newMonth))) {
else if (!(oldMonth.equals(newMonth))) {
download report
}
它必须返回到for循环请确认从何处比较旧月份和新月份。我告诉右静态设置一个txt文件=2015年10月为月份,从txt文件我将比较字符串。新月份将从所选内容中的所有内容开始。全部=2015年10月,1月=2015年10月等等。我的问题是在读了1月之后,应该读12月,但跳到11月。这就是问题所在。我不想把旧的月份当作十二月。
// your given url
driver.get("http://www.depreportingservices.state.pa.us/ReportServer/Pages/ReportViewer.aspx?%2fOil_Gas%2fOil_Gas_Well_Historical_Production_Report");
// take everything inside the dd inside the list
List<WebElement> allOptions = driver.findElements(By.xpath("//*[@id='ReportViewerControl_ctl04_ctl03_ddValue']/option"));
System.out.println("Size is : " + allOptions.size());
String oldMonth = "Dec 2015 (Unconventional wells)"; // old value that will come form a .txt file
for(int i=0;i<allOptions.size();i++){
System.out.println("Values inside the REPORTING PERIOD : " + allOptions.get(i).getText());
// now compare old month value with drop down value if matches then perform your action or in your case if not matches then perform your action
// if(!allOptions.get(i).getText().equals(oldMonth))
if(allOptions.get(i).getText().equals(oldMonth)){
// perform any action
allOptions.get(i).click(); // selecting value in the dd
driver.findElement(By.id("ReportViewerControl_ctl04_ctl00")).click(); //clicking on view report
break;
}
}
// Condition to check if the New month is equal to Old month, if it is not equal then proceeds
// to download that particular month data or else breaks the loop
if(!oldMonth.equals(newMonth)){
System.out.println(newMonth +"perform your action");
// download particular month data
}else{
System.out.println("newMonth matches with oldMonth");
break;
}