-4

I want to copy the whole page. No, not just text, but the whole page like we do with ctrl + a or select the whole page by dragging the mouse whole over the page where image with css also get's copied sometimes and I want that only! (for a quick demo: Just press ctrl + a on this page/any other site and paste it on Gmail or word doc. you'll see css with image also gets copied)

Achieving that with selenium isn't possible cuz it needs an element to interact with, where e.send_keys(Keys.CONTROL, 'a') or something like that doesn't work...

Is it possible using selenium? or do we need some other library to perform this task?

I want to do all that behind the scenes, i.e I don't want my chrome to open up. It should perform the task and it should be hidden...

Also note: Language is not an issue. Any language will be ok to perform this task.

  • You can get the root element https://stackoverflow.com/questions/37414306/cant-find-root-elements-with-remotewebdriver-findelementsbyxpath and send the copy all and copy keys. This works even if Selenium is run headless https://stackoverflow.com/questions/53657215/running-selenium-with-headless-chrome-webdriver – Martheen Jul 28 '20 at 06:19

1 Answers1

0

For Selecting all the content of the page you can use 'body' tag as a selector and perform Ctrl + A and Ctrl + C keypress. like below -

driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'a')
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'c')

And for running browser in a headless mode, you can set that option like -

chrome_options = Options()
chrome_options.add_argument("--headless") 

For more information please take a look at the given URL - https://medium.com/@pyzzled/running-headless-chrome-with-selenium-in-python-3f42d1f5ff1d

Swaroop Humane
  • 1,770
  • 1
  • 7
  • 17