[Selenium] using White to interact with Open File dialog box

2,592 views
Skip to first unread message

umar kayani

unread,
Nov 1, 2013, 12:06:38 PM11/1/13
to teststa...@googlegroups.com
Hi Guys

I'm hoping someone can help me out on this issue, it's really irritating me, as i've searched around and found nothing to my particular issue

I have a web application that i'm trying to test using Selenium, at some point during use of the app, I need to access an OS-level dialog box for choosing a file to open / import

I'm using Webdriver and C# with TestStack White

my code is as follows

 public void ChoosingFileFromImportDataDialog()
        {
            _driver.Manage().Window.Maximize();
            _driver.FindElement(By.Id("expandWorkflow")).Click();
            _driver.FindElement(By.Id("upload")).Click();
            _driver.FindElement(By.ClassName("qq-upload-button")).Click();
*** When I press the "qq-upload-button" an Open File dialog pops up ****
 up to this point it's fine, the below stuff for White is the issue :(
            Process pro = Process.GetCurrentProcess(); // get the process for the webdriver (ChromeDriver in my case)
            Application app = Application.Attach(pro) // pass the webdriver as an "application"
            Window mainWindow = app.GetWindow(SearchCriteria.ByText("Spider"), InitializeOption.NoCache); // Get hold of the browser by looking for it's Title "Spider"
            Window modalWindow = mainWindow.ModalWindow(SearchCriteria.ByText("Open"));
            modalWindow.Focus();
            Button cancel = modalWindow.Get<Button>(SearchCriteria.ByText("Cancel"));
            cancel.Click();

However it doesn't seem to work, my nunit runner says that it couldn't find an application with the Title "Spider"

Apologies if it doesn't seem clear, i'm very new to the White framework, I'll certainly try to clarify as best as I can

Thanks In Advance

Umar

Jake Ginnivan

unread,
Nov 4, 2013, 3:03:39 AM11/4/13
to umar kayani, teststa...@googlegroups.com
It may be because the browser window has appended something for instance. 'Spider - Mozilla Firefox'

Check in Visual UIA Verify, or with inspect.exe.

Sent from my Windows Phone

From: umar kayani
Sent: ‎01/‎11/‎2013 16:06
To: teststa...@googlegroups.com
Subject: [Selenium] using White to interact with Open File dialog box

--
You received this message because you are subscribed to the Google Groups "TestStack.White" group.
To unsubscribe from this group and stop receiving emails from it, send an email to teststack_whi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

umar kayani

unread,
Nov 4, 2013, 3:47:22 AM11/4/13
to teststa...@googlegroups.com, umar kayani
Hi Jake

Thanks very much for your reply

I forgot to mention in my original post that I'm also using UIAVerify to check the dialog box name and browser title

Jake Ginnivan

unread,
Nov 4, 2013, 6:08:09 AM11/4/13
to umar kayani, teststa...@googlegroups.com

Try using the overload which takes a string (the window title) rather than the search criteria.

umar kayani

unread,
Nov 4, 2013, 7:16:15 AM11/4/13
to teststa...@googlegroups.com, umar kayani
Hi Jake

Very sorry to bother you on this, but it seems that even if I try to do 

Window mainWindow = app.GetWindow("Spider - Google Chrome");

It still tells me that it can't find a window with the above title (that's run in NUnit btw)

if it helps, i'm attaching the current process (web browser) as the application to load, then doing my normal Selenium stuff, once i've got it to click on the "Upload File" link, at that point I use the WIndow mainWindow.... line of code and then try and go through to the modal window from that mainWindow, but to no avail 

Jake Ginnivan

unread,
Nov 4, 2013, 3:50:32 PM11/4/13
to umar kayani, teststa...@googlegroups.com

Not a problem.

 

Try going Debug.GetAllWindows() then print that out..

 

Otherwise use Desktop.Windows() then search through the windows that way. It will be a lot slower.

 

You can also try app.Windows() which should give you all windows for that process.

 

Let me know how you go.

 

Cheers,

Jake

umar kayani

unread,
Nov 5, 2013, 3:53:14 AM11/5/13
to teststa...@googlegroups.com, umar kayani
Hi Jake

Thanks for the different approaches

When I try Debug.GetAllWindows(), there isn't a method by that name available :S

When I try the Desktop.windows(), it returns all my current windows, but after each one it says something like the below

[Warn - 08:48:43] 'TestStack.White.UIItems.UIItem' Window with title: Spider - Google Chrome whose dimensions are: -8,-8,1936,1056, is not contained completely on the desktop 0,0,1920,1080. 
UI actions on window needing mouse would not work in area not falling under the desktop

Do you think it could be an issue that the actual process isn't there? I call my web page, then in the White section, I get the current process and then attach the process instead of giving it an .exe 

Sorry for inconvenience 

Jake Ginnivan

unread,
Nov 9, 2013, 7:31:47 AM11/9/13
to umar kayani, teststa...@googlegroups.com

Do you mean that your browser window is there?

 

If so, then maybe try Desktop.Windows().Where(w=>w….) to filter and try and get the window. Then once you have the window you can try and inspect it to see why you can’t get it.

 

If not, or another idea. Is the browser running as admin and your test process not? Or vise-versa.

 

They have to be running at the same level otherwise UIA doesn’t work properly?

 

Running out of ideas J

Reply all
Reply to author
Forward
0 new messages