find out if IWebBrowser2.ExecWB print was cancelled in C# - c#

I am using internet explorer to print a html document like this in C#:
ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER,
2, null);
This works fine, but I would like to know if the used pressed print in the dialog or cancel.
Is it possble to get this information without a ugly window hook hack ? something like a certain out parameter ?

This is not possible. I had this problem and ended up testing all possible values for the last output parameter, the output parameter is not used for this command.

Related

Playwright C# - wait for input text to be empty

I'm writing a test using Playwright with C# bindings, and I came across a problem with waiting for element input to have no text.
Before "add" action, input fields look like this:
Article Number input has id="Number", and Name has id="Name" - just to be clear.
After "add" action, input fields are cleared of text:
it's a matter of split second for inputs to be cleared of text, but Playwright doesn't wait for it and starts typing before clearing inputs, which messes up my test.
I've tried to use:
await page.WaitForSelectorAsync("#Number >> text=");
await page.WaitForSelectorAsync("#Name>> text=");
but it didn't help out.
How to wait for text to be empty?
I think your selector is asking Playwright to find an Element with no text. Input Elements store their contents in their Value attribute, so actually always have no text!
You can use this method to check an Input Elements value against a page object, or this method against an IElementHandle.
Maybe have a utility method, something like:
string inputValue = "input";
DateTime timeout = DateTime.Now.AddSeconds(5);
while(timeout > DateTime.Now && !string.IsNullOrEmpty(inputValue)){
inputValue = await page.InputValueAsync("#Number");
}
This will wait for the Input Element to have an empty value.
There is some caveats: Text= does check the value attributes on Input elements of type button & submit, as explained here.
Just in case someone else is looking for an answer to the same problem, Page.WaitForFunctionAsync(expression, arg, options) looks like the ideal way to wait for an element to be empty. The nice thing compared to the before mentioned solution is that it requires less code, the waiting is non busy, and there is less communication between client and browser, because the polling (until ready or timeout) happens inside the browser itself.
You can pass it the JavaScript expression (which will be executed in the browser), for example textBox => textBox.value == ''
And in the second parameter you can pass it the element handle of the textBox.
(I didn't try this myself because I'm normally using PlayWright with NodeJS, but I think with these hints you'll get a long way.)
This may not have been available when the question was asked.
You can now do:
await Expect(page.Locator("#Number")).ToHaveValueAsync("");

How to Open Default browser and target an element?

Hi all I have done some google work and not come up with a great deal apart from using the browser within a From which I dont want to do.
Has anybody some sample code or a good resource that is detailed enough to get me on my way plesae
So for example
Process.Start("https://www.google.com")
and target the search element with a string and click search.
Using the default browser
Please help me...
Doing something like this would work:
string mySearchQuery = "this is a search example";
Process.Start("https://www.google.com/search?q=" + Uri.EscapeDataString(mySearchQuery));
If I'm understanding you correctly, this would use the default browser set in windows, then the query is just passed in as a GET request (that's the ?q variable).

View parameter values while debugging with method call of many parameters?

Let's say I'm degugging code and I reach a breakpoint where the line of code is something like this:
GetEmpInfo(empName, empLast, empSS, empDept, empBirth, empCity, empState,
empCountry, parm1, moreparms, evenmore, toomanyparms);
Is there a way to know what value each of those parameters has without going through each variable? I know there has to be a way; I just don't know where it is.
Thanks.
There are 7 good ways to do it -
1. Data Tip
2. Autos Window
3. Locals Window
4. Watch Window
5. Quick Watch Window
6. Parallel Watch Window
7. Immediate Window
Check this for more info
You can use the DebuggerDisplay Attribute
[DebuggerDisplay("{Param1} {Param1} {Param1}")]
And when you hover over the object you will see the values that are entered above

Sending/Setting a value to a Password Field on a Website

I have written a small application that needs to log in to a website to perform some actions.
The problem is that whenever I try to set the password field on the website it doesn't accept the password.
I have found a way around this by using the SendKeys function. The problem with that is that it requires focus and the program requires to run in the background.
Is there a way to do this?
Here is an example of how you'd set the Username Field:
WebBrowser.Document.GetElementById("field-username").SetAttribute("value", "UserName")
Any help would be great.
The answer to this question is as follows:
WebBrowser.Document.GetElementById("field-loginFormPassword").SetAttribute("maxLength", "20")
WebBrowser.Document.GetElementById("field-loginFormPassword").SetAttribute("value", "yourpassword")
By changing the "maxlength" value it allows you to set the "value" to the desired text and then you can submit the Form and it will accept it.
Try with mshtml or Html Agility Pack

How to detect Javascript pop-up notifications in WatiN?

I have a, what seems to be, rather common scenario I'm trying to work through.
I have a site that accepts input through two different text fields. If the input is malformed or invalid, I receive a Javascript pop-up notification.
I will not always receive one, but I should in the event of (like I said earlier) malformed data, or when a search result couldn't be found.
How can I detect this in WatiN?
A quick Google search produced results that show how to click through them, but I'm curious as to whether or not I can detect when I get one?
In case anyone is wondering, I'm using WatiN to do some screen scraping for me, rather than integration testing :)
Thanks in advance!
Ian
Here's what I came up with.
I read this question several times before I came up with the obvious solution..
Can I read JavaScript alert box with WatiN?
This is the code I came up with.. While it does force a delay of 3 seconds if the alert doesn't happen, it works perfectly for my scenario.
Hope someone else finds this useful..
frame.Button(Find.ByName("go")).ClickNoWait();
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
while (stopwatch.Elapsed.TotalMilliseconds < 3000d)
{
if (alertDialogHandler.Exists())
{
// Do whatever I want to do when there is an alert box.
alertDialogHandler.OKButton.Click();
break;
}
}

Categories

Resources