So, I made a web page on which I have a button that when clicked runs Selenium code (I'm writing in Python). I want my Selenium code to run in this existing, manually opened browser(in which I pre-opened this web page) rather than open new browser window. I already looked through all the similar questions here, but every answer requires opening chrome in debugging mode (which I want to avoid) or doesn't use this manually opened browser but some else. My idea is that there needs to be a way for me to get session id of my existing browser and "give" it to Selenium so it knows where to run. Any ideas, solutions? :)
It's officially not supported.
However, there is some working code which claims to support this:, Also this is in java I am sure you can make in your desire language
https://web.archive.org/web/20171214043703/http://tarunlalwani.com/post/reusing-existing-browser-session-selenium-java/
Related
I am searching for a way which allows me to interact with a webrowser (Firefox,Chrome/Chromium,Edge are the most important).
I am currently using pyautogui, to locate login,password fields to put the login data into them. But since you can extract much easier informations when you can use IDs or xPath or other identifiers on webpages, it would make sense to use that.
I tried Firefox with selenium but I run in some problems. Can I attache it to a user created session (do I need the processID or something like that?). (Can I choose between the normal private session of the current profile?
I need a solution which works on Windows and Linux(it would be nice if the major Linux distros would support it. But the most important distros are Fedora/Ubuntu for me.) mac would be optional but since I do not got any mac I am not able to test it anyway.
The way with debugger mode or similar does not work really well for me since the browser needs to get started in a special way.
Would it possible to use something like this:
Can Selenium interact with an existing browser session? ,
When I can retrieve the this information some how form the existing browser?
driver.command_executor._url
driver.session_id
(But when I understand that currently it only works with browsers started with selenium?)
When I use Selenum and start a browserwindow with it can I login to a website and the user is logged in on the webside on his browser window too(if they us the same profile)? (Or does selenium separate cookies?)
If you need additional information or have some hints please post them so I can see them.
Thank you in advance for your help
It seems that it is not possible to connect to a web browser which was opened by the user to my understanding. How ever I found two possible solutions which I am currently trying to evaluate.
Using pyautogui to access the web browser over scanned images and control it with keyboard and mouse. (It is possible to access the console with the right combinations too).
The other solution is maybe more stable. Writing an browser extension which controls the browser.
Are there any alternatives to Selenium that don't require a web driver or browser to operate? I recently moved my code over to a Google Cloud VM instance, and when I run it there are multiple errors. I've been trying to get it to work for hours but just can't (no luck with PhantomJS, Chrome and GeckoDriver - tried re-downloading browsers, editing the sources.list file e.c.t.).
The page I'm web scraping uses JavaScript to load in numbers, which I was I initially chose Selenium. Everything else works perfectly though!
You could simply use the request library.
https://requests.readthedocs.io/en/master/
https://anaconda.org/anaconda/requests
You would then need to send a GET or POST request to the server.
If you do not know how to generate a proper POST request, simply try to "record" it.
If you have chrome, got to the page you want to navigate, press F12, navigate to the "Network" section and write method:POST into the filter.
Further info here:
https://stackoverflow.com/a/39661536/11971785
At first it is a bit more confusing than selenium, but once you understand it its waaaay better in my opinion.
Also the Java values shown on the page can usually be simply read out of the java code which is returned by your request.
No web driver or anything required and a lot more stable and customizable.
I am trying to get the current url opened in my pc in any browser using python.
I tried selenium it worked but it opens up a new browser window. I only want to get the current url opened in the browser.
Any help would be appreciated.
use keylogger in python, that would easiest solution, orelse you should catch each and every packets in network.
Selenium isn't made for such purposes. It can be used to automate testing of websites or for website scraping. Selenium associated with a driver (like Chrome's driver for example) is just a fancy browser that let's you interact with it in a non-intrusive way.
If you need to interact with already running apps, you could attach to another process's memory and read stuff directly from there but it might be very messy.
Also, see: Interact with other programs using Python
I am trying to implement automation in Python, because they changed the way we access data in my work. We used to log into an Unix based terminal, while now by using a simcard we open a browser page in Firefox that emulates the terminal.
Here is my problem: I wrote a script to save a .txt file with the data I am interested in. But when I tried to run it at work, it didn't run, because the page wouldn't let me open it (even if I was logged in).
So I decided to use a dumb solution: I saved the Firefox page as it was open and ran the script locally. But... I can't find how to save the page opened in Firefox without having to type the URL in Python beforehand. I want to automate this step too.
Is there a way to save the page opened like this one, acting like a Ctrl + S shortcut?
I appreciate any kind of help! Thanks!
I'm new to web programming, and have recently began looking into using Python to automate some manual processes. What I'm trying to do is log into a site, click some drop-down menus to select settings, and run a report.
I've found the acclaimed requests library: http://docs.python-requests.org/en/latest/user/advanced/#request-and-response-objects
and have been trying to figure out how to use it.
I've successfully logged in using bpbp's answer on this page: How to use Python to login to a webpage and retrieve cookies for later usage?
My understanding of "clicking" a button is to write a post() command that mimics a click: Python - clicking a javascript button
My question (since I'm new to web programming and this library) is how I would go about pulling the data I need to figure out how I would construct these commands. I've been looking into [RequestObject].headers, .text, etc. Any examples would be great.
As always, thanks for your help!
EDIT:::
To make this question more concrete, I'm having trouble interacting with different aspects of a web-page. The following image shows what I'm actually trying to do:
I'm on a web-page that looks like this. There is a drop-down menu with click-able dates that can be changed. My goal is to automate changing the date to the most recent date, "click"'Save and Run', and download the report when it's finished running.
The only solution to this I have found is Selenium. If it werent a javascript heavy website you could try mechanize but for this you need to render the javascript and then inject javascript...like Selenium does.
Upside: You can record actions in Firefox (using selenium) then export those actions to python. The downside is that this code has to open a browser window to run.