-3

there I'm trying to make a Robotic Process Automation(called RPA) using python. There are two windows; one is excel and the other is web.

The Procedure is:

  1. Both excel and web must be opened before run the code(It never be changed, there are no alternatives)
  2. the data on the web is copied and pasted to excel file.
  3. done!

It looks easy... but, selenium cannot access to already opened web and cannot access to already opened excel file.

of course, it could be easy to access to new web and new or load excel.

It doesn't matter selenium and are not used.

Does somebody know how to solve it??

Thank you.

2 Answers2

2

I see what you are trying to do, but there are easier ways to do this. Some questions to consider:

1. Is selenium the right tool for the job?

Do you need to simulate an entire browser navigate and download the file, or can you use some code to more simply download the file? Simulating the browser seems like a good idea until you notice you can simply scrape the website.

Using something like requests to download a webpage and something like BeautifulSoup to extract the specific link for the .xlsx, you can perhaps more easily achieve what you are looking for.

If selenium is indeed needed you should look into how to download the file -- not copy and paste it into Excel. Copying the file from the browser will require you to figure out some things like how to paste it on Excel, and extract individual HTML tags... which I bet will be inconceivably hard.

2. Do you wish to modify the.xlsx file?

If not, you should simply download it to a specific directory in your computer, and open the file on Excel with Python. If yes, then you will have to look into tools like pandas.

Don't give up.

If you looking to get this project to work you gotta keep in mind that programming is 65%-70% research and 25%-30% actually programming. The above resources should get you started, but it is vague enough that you will have to do your own research to get it going.

felipe
  • 7,324
  • 2
  • 28
  • 37
-1

As per my knowledge, selenium will only interact with those windows, that are invoked by it, but not on those which were already open. But, here are some related threads said we could do it using remote WebDriver and Session ID, you could check them:

How can I reconnect to the browser opened by webdriver with selenium?

Re-using existing browser session in selenium

Can Selenium interact with an existing browser session?

From my point of view, if you want to access the already opened IE window and Excel Worksheet, I suggest you could try to use VBA.

More detail information, please check the following articles:

Understanding automation

Excel + VBA + IE = web automation

How do I set the value to an already open Excel workbook?

How to navigate to an already opened internet explorer window? (VBA)

Zhi Lv
  • 18,845
  • 1
  • 19
  • 30