I have seen a lot of posts about how to click "Enter" on the "Save as" window in Edge but none seem to be working. I am trying to download a file on my local machine but it seems that the ctrl + s works but enter doesn't. I am using the following:
using Framework.Core;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
using System.Threading;
using System.IO;
using System.Linq;
using OpenQA.Selenium.Interactions;
using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
using SeleniumExtras.WaitHelpers;
The code that doesn't seem to be executing:
driver.SwitchTo().Window(driver.WindowHandles[1]);
Thread.Sleep(4000);
Actions savePDF = new Actions(driver);
savePDF.KeyDown(Keys.Control)
.SendKeys("s")
.KeyUp(Keys.Control)
.SendKeys("test.pdf")
.SendKeys(Keys.Return)
.Build()
.Perform();
The thing is when the invoice I want to download generates it automatically opens and focuses the new tab so I am not sure if I even need the driver.SwitchTo().Window(driver.WindowHandles[1]);
The first part where it clicks control s works but the second part where it supposed to, when the "Save as" window appears rename the file to "test.pdf" then click "Return" doesn't work. The "Save as" window appears but the test passes and the browser closes while the "Save as" window stays open.
I have also tried AutoIt and it same exact thing happens.
I have tried multiple ways but in the end I just stuck with disabling it asking for a download in pdf's. Edge sadly looks to be really limited compared to Chrome.
Related
First I tried to add extension directly from chrome webstore, but problem is alert popup which appears after you click "add to chrome" is not reachable by selenium. After I wanted to try using options.AddExtension, but multilogin profile starts before selenium takes control so this method is useless. I know that I can manually import .crx for every profile but there are thousands of profiles and I need to automate process of installing extensions. I don't know what to do, I heared there's option to reach popup alert in chrome webstore but can't find it. Or maybe there are other ways to install extension after browser started? I'm glad for any help or advice
I have 2 possible scenarios for you, hope that works out since I don't have direct access to this specific need you have because the extensions may differ.
Not using Selenium, you gonna start the chrome process using the class Process and add the flag --load-extension= to load the specific profile/extension that you need. You can see the entire comma here. To sum, you can use this snippet below to load:
chrome --user-data-dir=/tmp/someuniquedirname --load-extension=path/to/extension --no-first-run //Note: some flags may change between versions of chrome, see full documentation
After defining the extension and start chrome, you can now get hold of the process with Selenium by using another flag: --remote-debugging-port=http://localhost:[localporthere]. After that, start the process than tell to Selenium to get hold of that process with the port and do your job.
Another way is to start the process installing the extension manually and in another Thread use some Automation UI (Teststack.White or FlaUI) to click on the popup you have. I can't extend here in the entire code for this solution because it will go to a opinion-based answer, but you can check on FlaUI for that use, and follow that path:
Selenium starts the program, click on the install extension and wait for the popup to show-up;
New Thread;
FlaUI gets hold of the process that you already start;
Using UIElements, click on the "ok" button you need;
FlaUI drops;
Back to the main thread.
If you need any clarifications about the solutions above, just comment and I'll try to help you further.
I'm trying to make a program that will, on startup, open a WPF window and open a browser window. It is able to open the browser window and will still open the WPF visual-studio window thing when run by clicking on it, but when placed in startup it will only open the browser and will not open the other window.
When just placing the file in startup didn't work, I tried making a different program in startup to the original file, which would be somewhere else, but that has the same problem, even when not used on startup. I also tried adding a line to make the window show in addition to the InitializeComponent() step Visual Studio already added for me, but that didn't do anything. I couldn't find anything online that answered my question. Segments of code below:
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
public MainWindow()
{
InitializeComponent(); //Supposedly will open the window but doesn't
Window window = Application.Current.MainWindow; //Create an object reference to MainWindow
System.Diagnostics.Process.Start("https://www.website.extension"); //Open Browser Window
System.Media.SoundPlayer player = new System.Media.SoundPlayer("song.wav");
player.PlayLooping(); //Play song
window.Show(); //Force MainWindow to show (doesn't actually work)
}
The program is supposed to open on startup, but instead it only opens the website. When run in visual studio, it returns no error message and functions as normal. The problems only start when it is run by an outside source, such as startup or a different program.
Thanks for any help,
Nat
(I'm also pretty new to programming so try to explain what you mean if you use any big programming terms.)
I know this issue has been addressed a lot, but I haven't found a problem similar to mine, so please tell me if there's a solution.
I'm using selenium webdriver (chrome) and C# to test a web application.
In the application I have a button, which opens a windows file dialog in order to select and upload the file.
I am using Click() to click on the button and SendKeys() to paste the file's path in the windows dialog and to hit "Enter".
I'm not trying to control the dialog with selenium.
It's successful most of the time, but sometimes the dialog isn't opened once the button is clicked and it seems to be frozen for several minutes (it's impossible to click the button manually as well), but the test resumes as if the dialog had been opened. After 2-3 minutes the windows dialog finally appears, but needless to say that the entire test is messed up.
It is not a problem in the program itself, as the problem never occurres when the click is preformed manually.
What could be the problem and how can I solve it?
Please have in mind I cannot change the program I'm testing.
Thank you
You can do it without White using Microsoft UI Automation directly.
Without TestStack White. No sense to use the whole library for one window automation. White is wrapper only.
var FirefoxWindowElement = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty,"MozillaWindowClass"));
FirefoxWindowElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty,"#32770"))
//You can navigate directly to input field or just use the keyboard because input field is always focussed
SendKeys.SendWait("YOUR FILE PATH here");
Keyboard.Press(Key.Return);
What if you create a wait for dialog?
public void waitForElement()
{
while(!yourDialogElement.Displayed)
{
yourButtonElement.Click()
System.Threading.Thread.Sleep(1000) // sleep for 1000 milliseconds
}
}
You will probably want to build a try/catch into that button click, and perhaps build a counter into your loop and pass a timeout limit.
Let me know if this works or if you need more help!
You should consider adding a library called WHITE to your framework. This acts like Selenium but for Win32 applications and can handle most types of Windows dialog objects via Microsoft UI Automation.
With WHITE set up, you can add a method at the point in your code where the button is clicked by Selenium that opens up the dialog window. This method can poll for the presence of the dialog and if, after a set time, the window does not appear you could either fail the test there and then or try clicking the button again.
You could also poll indefinitely until the window appears if you are confident it always will. I would set an upper limit myself though to 5 minutes or whatever you feel is right here to prevent some sort of infinite loop situation.
I have designed an application which should greet the user when he turns on his computer.The program works well on my pc ,but when I transferred the .exe file of the program on my brother's computer it doesn't work meaning that "it doesn't work automatically when the pc boots"...How can I overcome this problem?? this is my code
Note:the program runs well if i executed it manually,but I want it to work automatically.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.IO;
namespace helloMSG
{
public partial class Form1 : Form
{
RegistryKey reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
public Form1()
{
InitializeComponent();
reg.SetValue("My app", Application.ExecutablePath.ToString());
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
`
If you want the program to start after Windows has booted then copy the executeable to the Startup directory:
Click the Start button Picture of the Start button , click All Programs, right-click the Startup folder, and then click Open.
Open the location that contains the item you want to create a shortcut to.
Right-click the item, and then click Create Shortcut. The new shortcut appears in the same location as the original item.
Drag the shortcut into the Startup folder.
Here is the source: http://windows.microsoft.com/en-gb/windows/run-program-automatically-windows-starts#1TC=windows-7.
If the program does not run on your friends PC, then make sure the .NET version is correct. There may be more information in Event Viewer telling you what the problem is.
The target computer should match requirements, at least the correct .net version should be installed and other dependencies, if any.Besides admin privileges might be required since you are writing to registry.
One more thing. You really don't need a winforms application for that. A Console one should do.
When an application or a small program is written and opened in chrome/firefox it is showing "Prevent this page from creating additional dialogs".
How might I stop this error through a C# program and not through modifying about:config, chromejs, or userchrome.css. I need this to work for each and every user using the application..
Is this possible?
This is Browser Behaviour, I don't think you can change it.
Or create your own dialog box.