Uploading a file in a popup window - watin

I'm using WatiN automation tool. I've got a scenario where I need to click on a button, which opens a pup-up from which I need to upload a file. I tried using Fileupload but it is not working, because the file selection window appears and closes immediately without uploading the file. Please suggest a solution. Below is the code I'm using:
ie.Button(Find.ByText("Upload_File")).ClickNoWait();
//now popup appears
IE popup = IE.AttachToIE(Find.ByUrl("http://localhost/admin/Uploadfile.aspx"));
popup.Fileupload(Find.ById("upload1_File")).set("D:\vinay\watin.zip");

Why don't you just set the field (that hold the path) without showing the pop-up, or clicking any buttons? All you need is get the text field Id & do something like:
ie.TextField("Upload_File_Path_Field_ID")).Text = "D:\vinay\watin.zip";

I am facing similar issue but using FileUploadDialogHandler
FileUploadDialogHandler fileupload = new FileUploadDialogHandler(filepath);
using (new UseDialogOnce(browser.DialogWatcher, fileupload))
{
browser.Frames[2].Div(Find.ById("draftTempMaterialFileDiv")).Span(Find.ByText("Document Attachment ")).ClickNoWait();
browser.FileUpload(Find.ByTitle("Choose File to Upload")).Set((#"E:\TEST_PROJECTS\3DLEX_New_Lib\TEST Template.docx"));
}
Though I have not yet figured out how to actually click on Open button, this code solved the issue of file selection window immediately closing

Related

VB6 - break program until a button is clicked

I'm using VB6 and I'm trying to do the following:
I have a command button that execute a while statement. in this statement I'm loading a new form with:
Load FrmPayment
FrmPayment.Show
I want the program to brake until I click a button in the new form, and then start from the same point I left
I tried looking the web for an answer but couldn't find anything that helped.
How can I do this?
By showing your new form modally the new form is the only form in your application that responds to the user.
Load FrmPayment
FrmPayment.Show vbModal

How to click on the `OK` button on the confirmation window using selenium-webdriver?

I am writing a file deletion script using selenium-webdriverfrom the webpage. Now when I clicked on the RED cross button as in the below image,getting another confirmation window on the page.
Any idea how to click on the OK button?
Have you tried with below logic?
Alert alert = driver.switch_to.alert
alert.accept
The below code finally works to handle the picture mentioned modal window:
driver.switch_to.alert.accept

reload after customize

i have a very simple firefox addon that essentially just displays the total number of open tabs.
So far it works beautifully, however after right clicking on the toolbar and selecting Customize… it only shows the default text until a tab is opened or closed.
i presume that i need to add an event listener for this event and call updateWidget(), however i can't find it in the API doc. So does anyone know how to do it?
Verified as bug, see : bugzilla.mozilla.org/show_bug.cgi?id=773297

How to handle new browser pop up after clicking a js button in Watir?

I am trying to using watir in ruby, I am able open a browser,
enter some values to a username/password form, but then I press enter, then I click the submit button (actually it is pressing an enter, it is easiler to code), it would pop up a new browser windows for our application, then I found I have no control to the new browser. What can I do?
In addition to my problem, the new browser window got no menubar, no toolbar, no navigation bar, thus I cannot open the IE developer toolbar to find the name of the element in the webpage in the new browser.
By the way, my app can only support IE.
I tried the attach method, but it does work:
C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/watir/ie-class.rb:302:
in `attach_browser_window': Unable to locate a window with title of (?-mix:New browser title) (Watir::Exception::NoMatchingWindowFoundException)
from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/watir/ie-class.rb
:150:in `_attach_init'
from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/watir/ie-class.rb
:144:in `attach'
from test1.rb:36
Attach method is able to handle new window.
http://rdoc.info/gems/watir/1.8.1/Watir/IE.attach
for example
browser = Watir::Browser.new
browser.text_field(:id,'username').set 'username')
browser.button(:index,1).click
# popped up the new window
popup = Watir::Browser.attach(:title,'Foobar')
If you will use only the popped up window, you can overwrite browser variable instead.
You could try to authenticate like so:
examplehost.com/authentication?user=foo&password=bar
You could also try to remove "target" attribute (which is probably equal to "_blank") of that authentication form ( i'm pretty much sure you should be able to achive this with watir )
EDIT:
Also, there's this option:
ie2 = Watir::IE.attach(:title, ‘New Ie window, opened upon form submit’)
it can also attach by :url instead of :title
ok, there's possibly this solution that might work:
b = Watir::Browser.start "http://yourpage"
b.execute_script("document.getElementById('your-image-id').onClick = function() {}")
so, the idea is to get that image and overwrite it's onclick event

Displaying a page in Firefox without opening a new tab

I'm writing an editor that is updating a WYSIWYG view in the browser. As this update can happen often i don't want to open the page in a new tab. Is there any way other then using the ugly way of emitting keystrokes to enter the Open URL command and entering the URL (I'm doing this right now, but it's buggy if the user interacts with the system in the meantime).
I tag this as firefox but comments on other browsers are welcome.
Script given below changes location without opening new tab. I think it would be helpful.
TYPE IN ADDRESS BAR:
javascript:window.location.href = "http://www.yahoo.com";

Resources