I do not want a modal window to appear - ruby

Im trying upload image. When I click on "Choose image", the modal window is displayed. But i do not want to show this window.
I have to click on "Choose image" because html attributes (to which I upload an image) are not visible for watir, after click on "Choose image" html attributes are visible.
Im using this for upload image to "Choose image" :
img_path = File.expand_path('../image/png.png', File.dirname(__FILE__))
after this i use this variable(img_path) and i set image to "Choose image".
Now i want take a screenshot but modal window is still here.
I used :
1) browser.modal_dialog.close
2) browser.send_keys(:escape)
3) browser.window(:title => Watir::FileField::WINDOW_TITLES).close
I tried use all "alerts" commands, which i found at watir.com GUIDES - ALERTS
I found this but it doesn't work as well: browser.windows.last.use
I tried to execute some scripts but without response: execute_script
So question is. How to block or how to do not show Windows or Browser window after click?.
Or do we have to change html so that this attribute is visible in html without clicking on "Select Image"? After that we can upload the image without clicking?
Modal window after a click
browser.iframe(class: "modalwin").present?
browser.iframe(class: "modalwin").element(xpath that click on choose image).click
img_path = File.expand_path('../image/png.png', File.dirname(__FILE__))
browser.iframe(class: 'modalwin').file_field(path to set file).set img_path
browser.iframe(class: "modalwin").element(waiting xpath).wait_while_present
browser.iframe(class: "modalwin").link(xpath that just click on button OK).click
This is my code that left the window open. Unfortunately.
This is my first question here so i hope everything will be ok. Thank you for your answers. I hope everything is written here. Otherwise, i will try to write better informations.

The problem is that what has popped up is neither a "Browser Window" nor an "Alert." It is not even controlled by the browser, but by the operating system. Since Watir can only control the browser, it can not dismiss it.
Watir allows you to upload a file without clicking on the element that opens that dialog box in the first place. So remove the line that clicks the image and just send the image path to the file field element. It should not enforce visibility in order to interact with it.

I found a solution. I hope it help to others.
You need to execute script like this:
browser.execute_script(
'HTMLInputElement.prototype.click = function() {'\
" if(this.type !== 'file') HTMLElement.prototype.click.call(this);"\
'}'
)
img_path = File.expand_path(opts[:image_path], File.dirname(__FILE__))
browser.iframe(class: modal_win).element(:xpath, choose_image).click
browser.iframe(id: modal_iframe1).file_field(:name, 'data').set img_path

Related

How winform's ReportViewer hides the "Exporting" window

I'm using The Viewer's reporting feature in Winform, Which has the ability to export pdfs, but before clicking on the export to pop up the save window, a "exporting" window will appear, I want to hide this window but I can't solve it after trying some methods, who can help me?
Click on the screenshot of the question
I tried something but couldn't solve it:
foreach(Form item in Applictaion.OpenForms){
//Hide this window
if(item.Title == "正在导出")
item.Hide();
}
I also tried this:
if (this.reportViewer1.Controls.Find("exportDialog", true)[0] is Form form)
{
//"exportDialog" may be the Name property value I tried to find in the source code, but it was prompted that "index out of range"
form.Hide();
}

Ruby Watir reference Chrome Print Preview

I'm writing a script to cycle through some links and print to PDF.
When you click on one of the links a new window pops up of the document to be printed and on top of that new window Chrome's print preview box pops up.
I'm trying to change the printer and then click the print button.
What's happening with my code however is that watir is only looking at the window html and not the print preview html so the elements are unable to be located.
My code looks like this:
begin
browser.window(title: 'Window Title Name').use do
browser.div(:id => "navbar-scroll-container").button(:class => "destination-settings-change-button").click
sleep(1)
browser.element(:title => "CutePDF Writer").click
browser.button(:visible_text => 'Print').click
end
rescue Watir::Exception::NoMatchingWindowFoundException
retry
end
I have tried using just "browser.windows.last.use do" instead of the title name but that also doesn't work.
I know it can only see the underlying window's html because when I puts browser.html the output is that underlying windows html.
If you want to look at the html situation just Ctrl+P this page (in chrome) to see what I mean.
Of course, after posting a question I soon found a sort of answer; basically chrome opens 2 browser windows and the print preview one couldn't be accessed by title (because it had the same title as the underlying one) but could be accessed by browser.window(:index => 1).use do. not sure why browser.windows.last.use do didn't work. Also following that I would have thought browser.window(:index => 2).use do would have been the correct one as index 0 would be the originally opened one, index 1 the popup and index 2 the print preview.

Click text-link image opens up in a box

I want to write code for a pop up when you click a text link like: "Click here for my CV". Upon clicking, I'd like a pop up with my image in it, not to have it open in a new window.
I tried with Lightbox but it didn't work for me. The image popped up in a new window, which isn't what I want.
How can I do this?
As far as I can see, you will need to prevent the default action caused by clicking the link.
here is a fiddle to help
https://jsfiddle.net/bsasi/xu58hb67/1/
$("a").click(function(evt){
evt.stopPropagation();
evt.preventDefault();
$(".lightUp").toggle();
});

How to create a background to keep button on it using resource editor

I am new to work on resource editor i have created two buttons next and previous to change the page in my own created window using CreateDialog function and resource editor.
Now i want to create a strip which i will put at the bottom of my window and I want to put the two buttons "NEXT" and "PREVIOUS" on that strip and that strip can be coloured (not be white). I want to do so because right now my buttons are on the display of image on my created window and which looks odd so i want my buttons to appear on the colourful strip(just like as you can see for .pdf files preview on preview pane) .
Any ideas how to accomplish it ?? I tried to use "COUSTOM CONTROL" option from the toolbox and wanted to colour it and wanted to put button on it but when i run the programme i found that before i had an image display at preview pane but now it is not working(i mean on putting the "COUSTOM CONTROL" on my IDD_MAINDIALOG the preview of the image don't work any more which was working before but when i put "MFC BUTTON" (just to check if it works or not ??)on my IDD_MAINDIALOG then it works(i mean there is no problem in dispaying the image on my window which had stopped working due to "COUSTOM CONTROL") )
So any ideas how to accomplish this strip creation ??
Maybe it would be easier to put the image inside a picture control rather than putting the buttons inside a strip.

Issue with IFrame - Selenium

Consider a webpage contains a IFrame, in that IFrame it contains only one
text box and a close button is present outside the IFrame.
According to this scenario,
how to click on the close button by filling in some values in Iframe text box
i.e First thing is to select the Frame using the command selenium.selectFrame("1_frame"); and
enter the text using the command selenium.type("id=name","test");
Problem here is,I need to click on the close button which is present outside the Frame.
What command should I use to click on the close button, present outside the frame?
How should I bring the focus to close button ?
Can any one help me out!
Thanks in advance .
After entering value in text box set focus to main window if close button is not part of IFRAME. You can do this by selectWindow("null") command.
Use Xpath or css path of close button and then perform click(Xpath).
If you are using firefox you can use firebug to get xpath or css path.
If it is not in iframe u can even use click(id or name)
if your IFRAMEs are Static then it can be handled easily.
If dynamic iframe present then You have to work from framework label.

Resources