I am using selenium webdriver for Python 2.7:
Start a browser: browser = webdriver.Firefox()
.
Go to some URL: browser.get('http://www.google.com')
.
At this point, how can I send a 'Save Page As' command to the browser?
Note: It is not the web-page source that I am interested in. I would like to save the page using the actual 'Save Page As' Firefox command, which yields different results than saving the web-page source.
Unfortunately you can't do what you would like to do with Selenium. You can use page_source to get the html but that is all that you would get.
Selenium unfortunately can't interact with the Dialog that is given to you when you do save as.
You can do the following to get the dialog up but then you will need something like AutoIT to finish it off
from selenium.webdriver.common.action_chains import ActionChains
saveas = ActionChains(driver).key_down(Keys.CONTROL)\
.send_keys('s').key_up(Keys.CONTROL)
saveas.perform()
I had a similar problem and solved it recently:
@AutomatedTester gave a decent answer, but his answer did not solve the problem all the way, you still need to press Enter one more time yourself to finish the job.
Therefore, we need Python to do press that one more Enter for us.
Follow @NoctisSkytower 's answer in the following thread:
Python simulate keydown
copy his definition for classes and then add the following to @AutomatedTester 's answer:
SendInput(Keyboard(VK_RETURN))
time.sleep(0.2)
SendInput(Keyboard(VK_RETURN, KEYEVENTF_KEYUP))
you may also want to check out the following link:
How can selenium web driver get to know when the new window has opened and then resume its execution
You may encounter pop-up window and this thread will tell you want to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With