I am writing a script where I click on a button (Select Photo) which opens up a file upload (explorer) box. How am I to set my file name?
This is the code I'm using to click on the Select Photo button (ruby)
driver.find_element(:id, "fileUploadButton").click
I've seen some posts that says I do not need to click on the button but to send the path to the file/image I want to upload. So how would I upload a file on c:\temp\mypicture.jpg?
Here's my full and simple code.
driver.navigate.to "http://blah blah" #the real site is an internal site
driver.find_element(:id, "claimGiftButtonDesktop").click
sleep 5
driver.find_element(:id, "fileUploadButton").click
After clicking the fileUploadButton, that's when the explorer window will show. If I manually click on Open or double click on it, then a loading modal shows and the image is shown on the website.
Here is an IDE recording which works. I'm just having problems translating this into ruby.
open /PromoSite
click id=claimGiftButtonDesktop
click id=fileUploadButton
type id=fileInputElem #Value C:\\temp\\file.jpg
click id=viewProductPreviewButton
I've also added a screen shot. I click the button and the File Upload shows up. This should be something easy, so I must not be focusing on the correct id.
As I have no your code, assume we are testing https://encodable.com/uploaddemo/
#driver.navigate.to "https://encodable.com/uploaddemo/"
element = #driver.find_element(:css, 'input[type=file]')
element.send_keys "/full/path/to/file.jpg"
#driver.find_element(:css, 'input[type=button]').click
So, you should send the full path to the input field and press the "submit" button
I know this is coming a year late but I just started writing a script in Selenium/Ruby and it took me some time to figure it out so wanted to post my solution (and it was as simple as 2 lines!):
*the first line inserts the file path WITHOUT clicking on the browse button, key is to separate directories using double back slashes \\
*the second line clicks on the Save/Upload button
driver.find_element(id: "Document_upload").send_keys("C:\\Users\\me\\Desktop\\my_file.txt")
driver.find_element(id: "save").click
Related
Writing some tests I had to click on a link that leads to another tab then I needed to click on another link, that last step isn't working (Unable to find link "Example" (Capybara::ElementNotFound)).
Should I need to change focus to the new tab first? How do I do that?
Tabs are treated as new windows in Capybara, so you need to move to the new window using Capybaras window api. It will look something like
new_window = window_opened_by do
# here you are in the context of the original window but your actions are expected to open a new tab/window
click_link 'the link that opens the new tab'
end
within_window(new_window) do
# this is in the context of the newly opened tab/window
click_link 'the link inside the new tab'
end
# here you will be back in the context of the first window
new_window.close # if you want to close the tab that was opened
All I had to do was add switch_to_window(windows.last) before the action
I am performance testing a reporting system where you enter information and generate a report. The issue I have is the report is generated as a PDF file and presents a Save Dialog box.
As part of the test I would like to save the PDF file to disk. How can I do this?
Edit: Below is the dialog box I get when I click a button to download the report.
I need to somehow simulate clicking the "Save File" radio button and then "OK"
You can use "Save Response to a file" lister to save the pdf.
Check below screenshot for reference.
Link for further information.
Note while using this you dont have to worry about click a button. Your will get pdf in response and that will be save by the above listener.
Click on save is not sending any request to the server and hence it will not be recorded in jmeter.
Hope this helps.
I'm struggling with a feature.
I have a scenario where I click a hyperlink to download a CSV. I have the command to open the csv file sorted. Once that hyperlink is pressed, a pop up box shows up in Firefox and I need to select the Save File option then press OK.
I have no idea how to tell selenium to do this. I have a test code to confirm a new webpage has opened (below)
new_window=page.driver.browser.window_handles.last
page.within_window new_window do
current_url.should eql "https://...."
end
This approach doesn't work for the download pop up. I need to move to the pop up and press those two options.
Any help would be appreciated
You are missing one important thing: Once your hyperlink is pressed, Firefox directs the underlying operating system to launch a pop up. In other words, you are no longer dealing with Firefox, and therefore Selenium is completely blind to that modal window. Generally the solution is something like Sikuli, Robot, or some other framework.
Also, have a read through this: http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/
I am using AutoIT within Internet Explorer to navigate from one web page to another
The code I am using is:
_IENavigate($oIE, "http://www.google.co.uk")
However the web page that it is coming from displays a JavaScript popup box. I would like to click the OK button to allow the Navigation to proceed
I have tried using the following code:
ControlClick("Windows Internet Explorer", "", "[CLASS:Button; TEXT:OK; Instance:1;]")
However this doesn't work due to the fact that when the dialogue box appears the AutoIT process seems to pause itself.
The title on the dialogue box is "Windows Internet Explorer" and there are two buttons. The button I would like to click has the text of "OK"
Has anyone else come across this before? If so how can I solve this problem?
_IENavigate by default waits until the page is fully loaded. The dialog box may prevent a page to be fully loaded. The correct solution would be to:
_IENavigate the page without waiting for the page to fully load
Wait until the dialog box appears and close it
Wait for the page to fully load
The parameters for _IENavigate are like this, and you need to set $f_wait to 0:
_IENavigate(ByRef $o_object, $s_url [, $f_wait = 1])
To wait for the dialog box to appear, you will probably simply repeatedly attempt to click it until the ControlClick function returns it did so successfully.
I would like to know how to bypass " Do you want to view only the webpage content that was delivered securely?" dialog box using VBscript ..
I am trying to open a webpage through IE in XP and after I login this dialog box appears.. and the contents of the pages are loaded.
I would like to bypass the dialog box.. I tried with Sleep and Send keys but didn't work because when the page is loading the script waits for sleep time and executes but actually that dialog box doesn't appear during that time (ie its all based on internet speed)
I would like to have a nice solution for this which works perfectly.
Thanks to all..
Your answer is here.
Here are the steps you need to take:
A) Open Internet Explorer and click on “Tools” and click “Internet
Options”.
B) Click on “Security” tab and click “Internet”.
Under “Select a zone to view or change security settings”.
C) Click “Custom level” under “Security level for this zone”.
D) Scroll down to the "Miscellaneous" section.
E) Select “Enable”
under “Display mixed content”.
F) Click “OK” and “Apply” to save
the settings.