This is somewhat similar to question about Is there a better way to get the page count from a PrintDocument than this?
But in my case I have a web-browser control with formatted html. At the moment I have option which calls ShowPrintPreviewDialog() so user can see how many pages going to be printed.
Is there anyway to get the no of pages which going to be printed, without launching the PrintPreview?
I am trying to create a method which will call OnTextChange and display print-page count automatically?
I have use PrintPage event
private void PrintDocumentOnPrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString(this.webBrowser1.DocumentText, this.webBrowser1.Font, Brushes.Black, 10, 25);
}
Bad news always travels slow at SO. You'll need to scratch the idea that this is practical.
Although unstated in the question, you should have already figured out by now that your PrintPage event handler doesn't work. It always produces a count of 1. That's because you never set the e.HasMorePages property to true, the property that causes more than one page to be generated.
To reliably set that property to true, you need to figure out exactly how the HTML gets rendered by the browser layout engine. And figure out exactly how to break it up into pages that don't cut, say, a line of text or an image in two. And figure out how to this is in the exact same way that the browser printing engine does this. A feat that's been attempted by many a programmer, accomplished by none. The browser's automation object model just doesn't have the needed api.
The only reasonable way is the one you already know. You have to call ShowPrintPreviewDialog(). Which readily displays the page count in the preview dialog, looks like this in IE11:
In case you'd consider snooping that number off the dialog: no, that cannot work either. The dialog doesn't use any controls, it is one monolithic window.
Related
im trying to make an automation with Watin and i'm having an issue reaching to a text fill in an HTML body..
when i log into the site i manage to reach the search box and to put input there and even press "enter" when it moves to the second page, i cant reach the input form there
This is my code - first step is working smooth but second isnt.
browser.GoTo("mywebsiteaddress");
browser.TextField(Find.ByName("sysparm_search")).TypeText(ticketNumber.Text);
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
//browser.TextField(Find.ByName("sys_display.sc_task.u_category")).TypeText(ticketNumber.Text);
browser.Element("sc_task.work_notes");
This is the Browser source code when i check it with google chrome
<textarea wrap="soft" onkeypress="" onkeyup="multiModified(this);fieldTyped(this);" onfocus="this.isFocused=true;" autocomplete="off" data-charlimit="false" rows="16" id="sc_task.work_notes" data-length="4000" style="; width:100%; overflow:auto; " name="sc_task.work_notes" onblur="this.isFocused=false;" onchange="this.isFocused=false;multiModified(this)" onkeydown="multiKeyDown(this);;"></textarea>
Thanks all!
It could be a number of things including what you're looking for is in a frame or less likely you're looking for it before it is loaded. If in a frame, you'll need to specify which frame. If it is not loaded yet the easy way to check is by putting in a generic sleep() call, though that is not the best long term.
When I deal with something I can't find, I make heavy use of the Flash() method. In your case, you'd probably want to start at the whole page level and work your way down to your object. Flash() will show you where you're looking at to make sure you're looking in the right spot on the page, ideally getting down to the parent element of what you're looking for and being able to correctly identify and flash that and then figure out what is amiss with trying to get the textarea you're really trying to get at.
Use Fire fox. Install an add on by the name Firebug.
Whichever element that you want to inspect, you right click on it and say inspect element with fire bug.
once you know the id or name of that element, you can easily access it using the Find class.
Sometimes it so happens that the element is in a different frame than the main frame. watin cannot directly access that element if it is not accessed via the frame.
We have automated a few test cases using the Ranorex automation framework for a Silverlight web application. These test cases involve clicking buttons in order to invoke certain messages on the screen. In order to grab the button on the screen, we first create an Ranorex button object and then point it to the appropriate element using Ranorexpath. Then, we use the RanorexButton.Click() event to click the button. However, this event is unreliable. It works sometimes and at other times the button is not clicked. When the button is not clicked, we have to run the test case again from the start. What are we doing wrong? If this is a known problem of ranorex, please suggest workarounds.
I was facing the same problem but I am able to resolve the problem by introducing a Validate.Exists(infoObject) just before the click. Please make sure that you pass infoObject of your button or any element in Validate.Exists API.
Example:
Validate.Exists(repo.MyApp.LoginBtnInfo);
var button = repo.MyApp.LoginBtn;
button.Click();
With regards,
Avinash Nigam
I haven't heard about such a problem with Ranorex yet, maybe this is just a timing issue.
You could add a Validate.Exists(yourButton) right before the click, this ensures that the click is performed after the button was successfully loaded.
If it is a WebElement you could also use the PerformClick() method instead of the normal Click() method.
There are also different methods which will ensure that the button is in the visible area and has focus, like the EnsureVisible() or the Focus() method.
You will find the available methods of the used adapter in the online API of Ranorex.
If the Button is not within the area you can see without scrolling, you can use a
var button = repo.Buttons.button1;
button.EnsureVisible();
button.Click();
In this way the button is forced to be watched.
It might as well be an issue with the xpath and element Id-s.
If you have changing element Id-s even when the page is navigated away from and moved back (for example we have this issue with SAP related components) you might need to make a more robust xPath path variable using regular expressions.
Try to find object and parts of the path that do not change (eg. "iFrame id="MainContent"" or "btn id="ID_XXXX_Search_Button"") - ofcourse this will only help if the issue is within this.
Ranorex Regular Expression info can be found here: http://www.ranorex.com/support/user-guide-20/ranorexpath.html#c3294
A quick example of what I'm talking about:
Let's say we have an input field that has a changing ID in it's name:
US_EL.ID_F2B49DB60EE1B68131BD662A21B3432B:V_MAIN._046A-r
And I know that the part in the Id that doesn't change is:
:V_MAIN._046A-r
I can create a path for this searching the element by the ending of the elements' id that doesn't change using regular expression:
/dom[#domain='test.example.com']//iframe[#'identifier']//iframe[#'identifier2']//input[#id**~'^**:V_MAIN._046A-r']
The bold part will specify to search for an input element with an Id that ends with ":V_MAIN._046A-r".
An issue that might arrise from this is if you have elements using partially the same names you might get multiple elements returned for the same path. So it's wise to add a few more certain points to the path (eg. "iframe[#'identifier2']") when this issue arrises.
I want to create my own custom graphic based on some parameterized data and have it be generated in a subreport. I placed a ActiveReports.Picture element on the report. I then drew my image in memory using the System.Drawing.Graphics object and then set it to the Image property of the Picture control. This works OK, but the image on the generated PDF is blurry, even after setting the pdfExport1.ImageQuality to highest.
I think it would be better to draw directly on to the ActiveReports Document canvas, but I can't figure out how to make that work. All the examples out there point you to the same basic example:
http://www.datadynamics.com/Help/ActiveReports6/topic2107.html
The problem is that the example is out of context. I don't see where this code should run? Inside the sub-report? In the calling report? Outsize the report entirely? When I tried it in the report, the Pages property had no pages (got an index out of bounds error), so I may be doing it in the wrong event.
To be clear, this is not a data-driven report. I get all the data I need via parameters. No DB access is required.
Thanks.
In the examples in the documentation you referenced, the DrawLine is drawing on the parent document/report (not the subreport). You can however draw on a page as a section is processed. To do that, you put your rendering code inside of the processing events of the section such as BeforePrint event or AfterPrint event (I would avoid using the Format as there are many caveats when using Format).
To draw on the page from within a section's event, you can find the location of the section from the Section class' CurrentLocation property. For example, to draw a diagonal line across the entire section from the BeforePrint event you could use the following code:
public void Detail_BeforePrint(object sender, System.EventArgs eArgs)
{
this.CurrentPage.BackColor = System.Drawing.Color.Purple;
this.CurrentPage.ForeColor = System.Drawing.Color.YellowGreen;
this.CurrentPage.PenStyle = DataDynamics.ActiveReports.Document.PenStyles.Dot;
this.CurrentPage.PenWidth = 4;
this.CurrentPage.DrawLine(Detail.CurrentLocation.X, Detail.CurrentLocation.Y, this.PrintWidth, Detail.Height);
}
This code should work fine within a subreport or a parent report. Apparently you will need to change this.CurrentPage to ParentReport.CurrentPage if you want to draw on the page from within a subreport. If you want to draw relative to the page, you can use similar code but use the PageEnd event. There is a good example in the PageEnd Event's documentation. However, the PageEvents will only work for the parent report, it may be difficult to orient the drawing coordinates relative to a subreport's location.
It seems you have to draw on the main page, even from the subreport, which is why CurrentPage is null. So the following from the subreport works:
this.ParentReport.CurrentPage
http://www.datadynamics.com/forums/118838/ShowPost.aspx
I'm looking for algorithm/library (preferably in c#) that can detect changes in the content of an html page intelligently.
For example if the page was techcrunch.com, it would only match when there's a new post or significant changes to the page. it would ignore html comments, javascript, minor updates such as the number of comments, etc...
Can someone point me to the right direction?
You could use JavaScript to count how many elements are on the page, or specific portion of the page. There are thousands of ways one could implement JS to detect changes.
For my assumption, that, you request the page with your C# program.
Actually, there are hundreds of ways to do it.
I'll give you one:
Number one, the easiest and dummy algorithm.. is
while(true) {
checkModifyDate();
if(date is newer) {
do anything you want...
}
do it again in next 10 mins()
}
That checkModifyDate() function will "ONLY" check the HTTP Header for changes.
Then you can do anything later.
You can add it to a timer object that runs every xxx minute or to a thread and set it to automatically do the job for you.
Hope this helps.
I want to implement a continious printing of document.Please see image belowalt text http://www.freeimagehosting.net/uploads/c87bde9396.png
When I choose the checkboxes then click the print button, all the information of a particular applicant will be printed.Take note that each document was printed on a new page. I found a soluton from this forum http://bytes.com/topic/asp-net/answers/861073-print-multiple-files-continuously
But I need an additional resources about this to implement the best solution for this functionality.Any ideas?
I believe that the best approach for this problem is to open a popup window with the contents using page break when necessary. This way you have better control over what is printed and you can give user a chance to review what is going to be printed if you like or call window.print on ready.