There is a drop downlist, where i need to compare the new values with a old month string= Sep 2015 (Unconventional wells). Then if not equals then that is a new month and it should be downloaded, or else come out of the loop. Can I put the List into ArrayList and compare the string?
Please help
WebDriver driver=new FirefoxDriver();
//opening the PA page
driver.get("http://www.depreportingservices.state.pa.us/ReportServer/Pages/ReportViewer.aspx?%2fOil_Gas%2fOil_Gas_Well_Historical_Production_Report");
//maximizing the window
driver.manage().window().maximize();
WebElement select = driver.findElement(By.xpath(".//*[@id='ReportViewerControl_ctl04_ctl03_ddValue']"));
//List<WebElement> options = select.findElements(By.tagName("option"));
String str="Sep 2015 (Unconventional wells)";
method below will pull out the current options of the dropdown to a List.
Best of Luck.
Pull the current 'Reporting Period' content to a List
/**
* Uses a {@link FirefoxDriver} to load the targeted website and extracts all current options of the 'Reporting
* Period' drop down to a List of String references.
*
* @return List of String references.
*/
private List<String> getCurrentReportingPeriodContent() {
// List to hold the value we will return to the caller.
List<String> currentOptions = new ArrayList<>();
WebDriver webDriver = new FirefoxDriver();
webDriver.get(
"http://www.depreportingservices.state.pa.us/ReportServer/Pages/ReportViewer.aspx?%2fOil_Gas%2fOil_Gas_Well_Historical_Production_Report");
// maximizing the window
webDriver.manage().window().maximize();
// This is the 'By.xpath' lookup used to find the dropdown field
By reportingPeriodLookup = By.xpath(".//*[@id='ReportViewerControl_ctl04_ctl03_ddValue']");
// Find the 'Reporting Period' drop down on the page.
WebElement select = webDriver.findElement(reportingPeriodLookup); // Find the drop down
// Pull out the options as web elements
List<WebElement> matches = select.findElements(By.tagName("option"));
// Traverse the web elements to extrat the text. Text gets added to the 'currentOptions' List
for (WebElement match : matches) {
currentOptions.add(match.getText());
}
// Clean up the webdriver
webDriver.close();
// return the List of Strings pulled out of the 'options' back to the caller.
return currentOptions;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.