Is there a way to determine programmatically, using Python, which web page is currently active in Google Chrome?
Google Chrome for Mac has added the AppleScripting method for getting the URL.
Here's the Chromium AppleScript SDK
https://sites.google.com/a/chromium.org/dev/developers/design-documents/applescript
Example from the page linked below:
tell application "Google Chrome"
get URL of active tab of window 1
end tell
More examples here:
http://laclefyoshi.blogspot.com/2010/10/google-chrome-ver.html
Not yet, it seems. Such tasks are done, with other browsers, via the Applescript interface, but, as this thread shows, while hotly requested for Chrome on the Mac this feature is not there yet.
(Once a Mac app does get a good Applescript interface, there are several ways to use that interface from Python, without needing to actually involve Applescript as a language -- this has been touched upon on other SO questions about other apps -- but the problem is that Chrome in particular doesn't yet support this quintessentially Mac-ish functionality).
Given the insistence of the request I'd expect somebody to eventually roll up their sleeves and contribute a patch for the purpose, but it doesn't seem to have occurred yet.
Related
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/
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.
Question:
Hi. I am a beginner trying to learn Python, and for one of my first projects I want to write a script that will fill out a survey automatically for me. I am familiar with coding, and I have most of the code written to solve this problem. What I am struggling is to write a method that will hit button #1 in question #1, or that will push any given button. One way I've realized I can do this, is perhaps by writing a script to press tab-> up-> down-> tab-> up -> down in the order needed to answer all of the questions.
Here is an image of what the survey looks like (CSS was disable for clarity).
http://i.imgur.com/Tn94KFA.jpg
What is one way to go about writing a method to push a radio button?
[Disclaimer]: I have checked out the following questions but they were of no use to me in my current situation:
fill out a webform that uses javascript with python (question was framed very strangely and was about Javascript forums, which I don't understand how it is relevant/ I didn't understand it, and nobody answered the question).
Script to take web survey for me (answers were only about Java, however something like this tool called HtmlUnit seems cool, if there were a comparable library in Python).
How to fill out form data on a website (question is about Java).
There are Python libraries and tools for automatizing browser actions. StackOverflow.com is not a place to ask for an recommendation for such a tool and thus moderators will close this question (SO is usually asking a help for particular problem, not for broad help and tutoriing requests). However here are some starting points for you
Splinter - automate browser actions in Python
Mechanize - Python library for stateful programmatic web browsing
Selenium automizing framework Python bindings - using full installed browser
Headless web browsing listing - includes Python ones
Scrapy - web content scraping framework in Python
For installing Python packages please refer to official package installation tutorial.
I am using python to write selenium-rc test code for my server code. The server application is written with ASP.NET and is configured with "Windows authentication". The execution steps of my python code look like the following:
Start python main()
Create the selenium instance (say sel)
Start the selenium by calling sel.start()
Open the target URL with the selenium instance via calling sel.open(url)
Windows authentication dialog box pops up at this time
sel.open(url) is, by default, set to time out in 30 seconds while the authentication process is pending for input of username and password.
At this point, I could not find any way through selenium-rc interface to make it recognize the pop up dialog box. I google around and find out that the selenium-rc interface (in python) is for http authentication only- not Windows authentication.
I have tried to use autoit within selenium but still without luck.
Can any of you shed some light on this?
Thanks in advance.
marvinchen
Selenium has issues recognizing that window (try to search HTTP Basic Authentification for more details about it)
Basically, only thing which kinda works is to put username and password into URL request itself. Assuming your application runs on http://example.com the new url should look like this:
http://username:password#example.com
This solution works for me, but only using Google Chrome as a default browser for testing
There is now way you can sort it out easy and at this point unless I have missed something last few months it will only be FireFox who can fix this for you.
Read this blog how to sort it out:
http://applicationtestingtips.wordpress.com/2009/12/21/seleniumrc-handle-windows-authentication-firefox/