How can I reverse "action.KeyDown(Keys.Alt).SendKeys("N").Perform();" in C#, Seleium/Appium/Visual Studio - selenium

I am testing uploading from file explorer window that has been opened via web browser application - for some reason it can find the open window but can't find File name field and doesn't actually click the Open button (despite passing that step).. As a result I have had to use alt + N to select the File name field, which is all well and good, but that results in disabling my keyboard for all other apps.
I presumed that I would only need to do a KeyUp on the alt button as there is no equivalent for the N key, which is obviously sent using SendKeys method... The code below DOES run, but it is far from ideal if I'm going to have to keep coding key strokes that I can't reverse unless manually...
if (open != null)
{
Actions action = new Actions(session);
session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
Thread.Sleep(1000);
action.KeyDown(Keys.Alt).SendKeys("N").Perform();
action.KeyUp(Keys.Alt).SendKeys("19th December 1932 (2).xlsx").Perform();
action.KeyDown(Keys.Alt).SendKeys("o").Perform();
action.KeyUp(Keys.Alt).Perform();

Does it work if you write the actions like this?
action.KeyDown(Keys.Alt).SendKeys("N").KeyUp(Keys.Alt).SendKeys("19th December 1932 (2).xlsx")Perform();
action.KeyDown(Keys.Alt).SendKeys("o").KeyUp(Keys.Alt).Perform();

Related

AutoIT send() commands not working properly

So I have a game client with 2 input fields: id pass and 1 button: login.
My login credentials are: $id=1234 and $pass=a_bCd.
I'm using AutoIT scripting to automate the login process (my script automatically inputs the id and pass in the login fields) and my AutoLogin() function looks like:
send($id + "{tab}")
Sleep(10)
send($pass + "{enter}")
Sometimes it works fine, but sometimes my script introduces 1234a- or 1234a_ in the ID field and the rest of the characters in the pass field. I tried many solutions like controlsend("Game","","","1234{tab}a_bCd{enter}"), or changing sleep() values, etc. but the input still goes wrong sometimes. Figured the send delay or sleep would have the problem, still don't know what to do.
Manually inserting the id and pass works properly. What would be a good solving of this problem? Thanks
I have had the same troubles with send. This post on autoitscript.com may help you with WinAPI_Keybd_Event() (documentation here):
#include <WinAPISys.au3>
_WinAPI_Keybd_Event(0x11, 0) # Push CTRL down
_WinAPI_Keybd_Event(0x11, 2) # Lift CTRL up again
This helped me with my problems.
NOTE: Sometimes, when your script breaks because of an error, it may happen that one of the keys on your keyboard is still pressed (i.e. pushed down but never lifted up). I use the on-screen keyboard that is integrated in Windows for these moments...
2 Solutions:
You add Strings with &:
send($id & "{tab}")
send($pass & "{enter}")
If that does not work just separate it:
send($id)
send("{tab}")
send($pass)
send("{enter}")
And you don't need that sleep

Automatic download of created file in Sencha Touch 2

My Sencha Touch 2 application has an 'Export' button, which creates an Excel file with the data of the selected offer.
After the user clicks the button, i want the (server side) export process to be started, and, once completed, the user to be prompted to select a filename and location, OR that the file is automatically downloaded. How do i do that? Does anyone have an example?
For Excel specifically I'm not 100% sure, but this might help you get started or if a CSV is acceptable...
I'm sure you could pass the file reference to a var instead of the string but I have yet to try it.
If you paste the js below into the console you can see how this works. Pretty basic. Maybe try the returned value from the server to see if that works then if it does you can build a function around it to happen when needed.
csvHeading = 'HA, HB, HC, HD \n';
csvData = 'r3a, r3b, r3c, r3d \n' +
'r2a, r2b, r2c, r2d';
CSVFile = csvHeading + csvData;
window.location = 'data:text/csv;charset=utf8,' + encodeURIComponent(CSVFile);

ControlClick not working with AutoItX3

I am currently trying to use AutoItX3 to do some automation.
My script opens up an application and now I want it to click on the certain button within the app. This is my code for the ControlClick (parameters were acquired from the AutoIt v3 Window Info Tool) :
Local $sText = WinGetTitle("[ACTIVE]")<br>
ControlClick($sText, "", "[CLASS:WindowsForms10.Window.8.app.0.33c0d9d; INSTANCE:62]", "left", 1, 21, 12)
Unfortunately, this code does not seem to do anything at all. I replaced it with a regular mouse click with coordinates, but then this script won't work on any computer with a different resolution.
Any ideas?
Try this to understand what I meant.
Example()
Func Example()
; Run Notepad
Run("notepad.exe")
; Wait 10 seconds for the Notepad window to appear.
WinWaitActive("[CLASS:Notepad]", "", 10)
ControlSetText("[CLASS:Notepad]", "", '', 'HELLO WORLD!')
; Wait for 2 seconds to display the Notepad window.
Sleep(2000)
ControlSend("[CLASS:Notepad]", "", '', '{Right 20}{ENTER}NEW LINE!')
; Close the Notepad window using the classname of Notepad.
WinClose("[CLASS:Notepad]")
WinWaitActive("Editor", "", 10)
ControlSend("Editor", "", '', '!n')
EndFunc ;==>Example
Are you sure that AutoIt spy tool identifies the button individually?Some times AutoIt info tool identifies a some portion of a application(multiple buttons or multiple tabs)as single object.In that situation you have to use the mouseclick opration and after that use control click function like below
mouseclick("",21,21)
Controlclick("","","button1",21,21)
this might help you.make sure to capture the x and y coordinates from the Mouse tab of autoIt info tool.
Sometime it could happend on some windows protected with an anti-bot/macro systems such as games, java clients etc...
You could by-pass this using a VM with a third-party desktop controler such as teamviewer/RDP/... You will be able to run your script thru the RDP session.
Please Note: AutoIt is not made to make GameBots :)
Vlu.

Can't find a popup window opened via target="_blank"

I am working with a website that has a form that submits a POST request and opens the target page in a new window using target="_blank". Firefox opens it in a new window.
When I do a loop like
String titles[];
do {
titles = browser.getAllWindowTitles();
System.out.println(titles.length);
} while (titles.length < 2);
It always prints out 1, even when the new window pops up and loads. How can I select this new window?
I am using DefaultSelenium. I have tried approaching it in other, indirect ways such as direct URL loading, but the site sends POST requests and I'm unable to simulate those.
Try the below alternative code and check if it is working as expected.
Set titles = browser.getAllWindowTitles();
Iterator i = titles.iterator();
while(i.hasNext()){
System.out.println(titles.size);
}

How to link a PDF Document to a Record using Visual Studio LightSwitch 2011?

I'm Stuck the following problem: How can I link a PDF Document to a Record in a Data Grid using Visual Studio LightSwitch 2011 and Visual Basic?
Any help would be awesome, thanks!
Here's the simplest way to do this: add a custom command to the Command Bar of the Data Grid Row for your Data Grid. In this example I'm calling the command Open PDF File. Then add this code to Execute code for the command:
partial void OpenPDFFile_Execute()
{
const string LOCAL_SERVER_PDF_DIR = #"\\MyServer\PDFs\";
const string WEB_SERVER_PDF_DIR = "http://myweb.server/PDFs/";
const string PDF_SUFFIX = ".pdf"; //assumes you do not include the extension in the db field value
if (AutomationFactory.IsAvailable)
{
//if the AutomationFactory is available, this is a desktop deployment
//use the shell to open a PDF file from the local network
dynamic shell = AutomationFactory.CreateObject("Shell.Application");
string filePath = LOCAL_SERVER_PDF_DIR + this.PDFFiles.SelectedItem.FileName + PDF_SUFFIX;
shell.ShellExecute(filePath);
}
else
{
//otherwise this must be a web deployment
//in order to make this work you must add a reference to System.Windows.Browser
//to the Client project of your LS solution
var uri = new Uri(WEB_SERVER_PDF_DIR + this.PDFFiles.SelectedItem.FileName + PDF_SUFFIX);
HtmlPage.Window.Navigate(uri, "_blank");
}
}
You will need to add the following imports to the top of your user code file to make this code compile:
using System.Runtime.InteropServices.Automation;
using System.Windows.Browser;
I should mention that you need a directory to server the PDFs up from. This example is flexible with respect to deployment, because it handles both desktop and web configurations. Since you'll need to set up the PDF directoy, you may want to just handle one configuration option to simply things (or you could expose the same PDF directory over http and as a local network share).
You may also want to present this as a true link instead of a button. In order to do this, you'll need a custom SilverLight control. In any case, I would recommend implementing the PDF link using a button first. You can then move this same code to a link event handler as a separate project if that is worth spending time on.