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?
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.
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