like page number=1,page number=2 ans so on,is there any pre defined attribute for that in dynamic report API,I know the question is too dumb,but still i could not find an answer to this question even through google,pls help.
If you want to add page no to your report you need to add this line to your report object
try {
report()//create new report design
.columns(...) //adds columns
.pageFooter(cmp.pageXofY()) //shows number of page at page footer
.show() //shows report
.print() //prints report
...
} catch (DRException e) {
e.printStackTrace();
}
Related
i am creating jasper report for view the student details. i have a textfield if the enter correct student id relavent student details display on the jsper report below. i called the jsper report inside the jpanel.
if i enter first time student id 3 it displayed result success then if i enter the second time student id 4 the same result shown. i don't know why.
HashMap a = new HashMap();
a.put("id", txtno.getText());
try {
JasperDesign jdesign = JRXmlLoader.load("C:\\Users\\kobinath\\Documents\\NetBeansProjects\\JavaApplication138\\src\\report1.jrxml");
JasperReport jreport = JasperCompileManager.compileReport(jdesign);
JasperPrint jprint = JasperFillManager.fillReport(jreport, a, con);
// JasperViewer.viewReport(jprint);
JRViewer vw=new JRViewer(jprint);
jPanel1.setLayout(new BorderLayout());
jPanel1.repaint();
jPanel1.add(vw);
jPanel1.revalidate();
} catch (JRException ex) {
}
I think that revalidate() alone isn't enough to refresh the panel. You may reference to this link to make sure that repaint() is better to be called.
I hope this helps you solve your problem.
P.S. You can swap the two lines before the last line.
I'm automating a webstore in selenium/Java. If the user hasn't selected the size of a product, a message comes up stating 'this is a required field' next to the size. I'm trying to write an 'if' statement that asserts whether this message is present and the action to take if it is, but I cannot get it to work. It would be something along the lines of this:
WebElement sizeIsRequiredMsg = driver.findElement(By.cssSelector("#advice-required-entry-select_30765)"));
WebElement sizeSmallButton = driver.findElement(By.cssSelector("#product_info_add > div.add-to-cart > div > button"))
if (sizeIsRequiredMsg.equals("This is a required field.")) {
action.moveToElement(sizeSmallButton);
action.click();
action.perform();
}
I've tried a few different variations using the 'this is a required field' message as a web element. Not sure if I need to convert the WebElement for the message to a string somehow? Or include a boolean? Can anyone help?
Try using getText() something like this:
EDIT I have added the correct cssSelectors and added try catch :
WebElement addToCartButton = driver.findElement(By.cssSelector("#product_info_add button"));
action.moveToElement(addToCartButton);
action.click();
action.perform();
try {
WebElement sizeIsRequiredMsg = driver.findElement(By.cssSelector(".validation-advice"));
WebElement sizeSmallButton = driver.findElement(By.cssSelector(".swatches-container .swatch-span:nth-child(2)"))
if (sizeIsRequiredMsg.getText() == "This is a required field.") {
action.moveToElement(sizeSmallButton);
action.click();
action.perform();
}
} catch (Exception e) {
System.out.println(e);
logger.log(Level.SEVERE, "Exception Occured:", e);
};
Hope this helps you!
In this application : task is to click on each report link one by one and get the header title of the report from the report page.
so it verifies that the report opens properly with data.
Since there is no common x path in the all reports, thus
to capture the report heading i applied a generic x path : that gives me list of headings in the report page .....later i collected the heading with zero index, ie. the main header
Problem 1: there are few reports where : this x path has no significance, it locate nothing .....and in these report there exists view button ...clicking on view opens the report
Problem 2: there are few report where heading format is align either in right or left
According to my code : it is difficult to catch them ......there are 4 out
of 80 such reports in a slot . where x path gives nothing as shown in
attachment
According to the code what logic should be applied to catch view ....
Using page Factory :
#FindAll({
#FindBy(how = How.XPATH, using = ".//table//tr[1]/th")
})
public List<WebElement> view_ReportPDf_page;
List<WebElement> lis= namedreportviewlinks;
///// TO get the report links within
int count=0;
for (int j = 0; j < lis.size(); j++) {
WebElement e2 = lis.get(j);
((JavascriptExecutor)
driver).executeScript("arguments[0].scrollIntoView(true);",e2);
e2.click();
for (String winHandle : driver.getWindowHandles())
{
driver.switchTo().window(winHandle);
}
Thread.sleep(1000);
List<WebElement> lis2= ld.view_ReportPDf_page;
for(WebElement headers:lis2)
{
headers=lis2.get(0);
System.out.println(headers.getText()+"--------------------"+count);
break;
}
driver.close();
count++;
for (String winHandle : driver.getWindowHandles())
{
driver.switchTo().window(winHandle);
}
}
ld.Dnetsubcategoryreport_backbutton.click();
}
If the View button is present under th tag then findElements() method can be used to check the presence of this button. If present, click on it else click on report link.
e.g.
if(driver.findElements(By.name("View")).size>0)
{
//logic to click on View button
}
else
{
//click on report link
}
If the reports table is the only table on the page, then elements can be located using tagName as th. (NOTE: All report links should be under th tag then this approach can be applied.)
Hope this helps!
I want to Print JTABLE and A value from Text Field. Its like products detail and there Bill Print.
Here is the image.
Required Print is Table + Total Amount,
But so far i got JTable.print() only print table. is there any way to add other values at end as total ??
Here is the code of printing jtable.
MessageFormat header = new MessageFormat("Purchases Bill {0,number,integer}");
try {
table.print(JTable.PrintMode.FIT_WIDTH, header, null);
} catch (java.awt.print.PrinterException e) {
System.err.format("Cannot print %s%n", e.getMessage());
}
Use jtextfield1.print(); I think it will work. It will only print the specified textfield.
I'm using HTMLUnit in order to put text in a input box and then clicking on a link which is actually a JS call.
The problem comes up when I put text in an input , using inputBox.setValueAttribute("example input"); . In this case , after clicking the button the page does not change at all.
On the other hand , once I delete inputBox.setValueAttribute("example input"); and then click the button, the page content does change and includes an error for empty input.
Below is the code i've used in order to put text in the relevant input and then click the button.
public void addressToBlockPlot(){
WebClient client = new WebClient(BrowserVersion.FIREFOX_24);
client.getOptions().setThrowExceptionOnScriptError(false);
client.getOptions().setThrowExceptionOnScriptError(false);
client.setJavaScriptTimeout(10000);
client.getOptions().setJavaScriptEnabled(true);
client.setAjaxController(new NicelyResynchronizingAjaxController());
client.getOptions().setTimeout(10000);
try {
HtmlPage page = client.getPage("http://mapi.gov.il/Pages/LotAddressLocator.aspx");
HtmlInput inputBox = (HtmlInput)page.getHtmlElementById("AddressInput");
final HtmlAnchor a = (HtmlAnchor) page.getElementById("helkaSubmit");
inputBox.setValueAttribute("example input");
a.click();
client.waitForBackgroundJavaScript(2000);
HtmlPage page2= (HtmlPage) client.getCurrentWindow().getEnclosedPage();
System.out.println(page2.asXml());
} catch (Exception e) {
}
}
Any ideas for solving this issue ?
EDIT:
I've tried using inputBox.setValueAttribute(""); , which resulted in receiving the same error that I got when no input text was set at all.
I have almost similar issue, where JS take some time to load, I have solved this issue by setting wait and retries until page load successfully by adding a condition,
int input_length = page.getByXPath("//input").size();
int tries = 5;
while (tries > 0 && input_length < 12) {
tries--;
synchronized (page) {
page.wait(2000);
}
input_length = page.getByXPath("//input").size();
System.out.println("page loaded successfully");
}
here input_length determines that whether required page is loaded or not. you can use similar condition according to structure of your page.