See what page is open in Google Chrome - java

I was wondering if it was possible to find out the URL of the page that is open in a browser, such as Google Chrome.
I was thinking the best way would be to make a Chrome extension that would log the current URL of whatever tab was open in a file, then the Java application would just have to read the file, but is there a way to do this without the extension?
I found Check what the current URL is in browser, but I was not sure if this was the same question, as the OP of that question was looking to complete it using the Selenium libraries, but still was not given an answer.
Is the extension the best way, or can Java do this without it?
Thanks.
EDIT: By the looks of things, Chrome extensions can't save files anyway, so I'm really not sure if this is possible.

Related

Is there a way to get all open URLs from the browser from JAVA?

I need to know what tabs are open in a browser, I was researching and found something about selenium, but it does not use the current section, it uses a session generated by it. Is there any other way to get open URLs from JAVA? . thanks for your help

Trying to upload a file from file explorer using java/selenium

I am trying to write a java program that uses selenium to perform web actions. In the case of uploading a video there is a frame where the user clicks that brings up the File Explorer for Windows. I have not been able to find anything that will help me in getting the focus to the File Explorer to select a file. There is no "browse" on the page with a textbox for me to just send a filename to.
Here is what the page looks like:
I would try using Selenide because it has a pre-canned upload utility that might save you some time/effort. See the command .uploadFromClasspath in the docs. One of the project videos/pages shows a little more detail on how to do it.
I've not actually tried it, but if this works for you and you figure it out, please share.
What I have done in the past is to use the "Apache HttpUtils" class to simulate the upload action from my test. All you need is the upload URL, and the HTML page usually provides that. That might also work for you.

Parse a page (partly generated by JavaScript) by using Selenium

I've got a problem: I want to parse a page (e.g. this one) to collect information about the offered apps and save these information into a database.
Moreover I am using crawler4j for visiting every (available) page. But the problem - as I can see - is, that crawler4j needs links to follow in the source code.
But in this case the hrefs are generated by some JavaScript code so that crawler4j does not get new links to visit / pages to crawl.
So my idea was to use Selenium so that I can inspect several Elements like in a real Browser like Chrome or Firefox (I'm quite new with this).
But, to be honest, I don't know how to get the "generated" HTML instead of the source code.
Can anybody help me?
To inspect elements, you do not need the Selenium IDE, just use Firefox with the Firebug extension. Also, with the developer tools add on you can view a page's source and also the generated source (this is mainly for PHP).
Crawler4J can not handle javascript like this. It is better left for another more advanced crawling library. See this response here:
Web Crawling (Ajax/JavaScript enabled pages) using java

Possible to check if a website is open in browser from java

Is it possible to check if a website is already opened in the default browser from a java program? I need my program to open a specific website before doing some other stuff. So is it possible to check whether this website is already open?
EDIT:
Ok, i'll try til explain the situation a little further. So i want to download some files from a webpage (http://aula.au.dk/main/document/document.php?cidReq=IMFFOUANAE12). When you click a file you're redirected to some file destinations where you can download it. My program list all these files, and then when you click a filename the browser opens the url that will redirect you to the download of that specific file. My problem is then, if the url i linked above isn't open i get an SQL-error from the website. Apparantly this error only show when the above url isn't open i an tab. So if i download a file, close the browser, try to download a new i get the problem. But as below, it seems cookies can help me out.
I'm not that in to all this http, website kinda stuff.
Regards
Jesper
No it is not possible to do the thing that you have asked.
I am not sure whether it is possible, you can open Default browser by using Desktop class. Or you can do
Runtime rt = Runtime.getRuntime();
rt.exec(new String[]{"C:\\Program Files\\Mozilla Firefox\\firefox.exe", "-new-window", "example.com"});
Why should you worry even if your page is already opened ?
Yes but even if you try to open same page browser will keep the session of old page.It will be tracked using jsessionid.
Please check the links using cookies you can do
http://www.mkyong.com/servlet/a-simple-cookie-example-in-servlet/
http://www.tutorialspoint.com/servlets/servlets-session-tracking.htm
Its not possible purely because Java has no way of knowing whether browsers are open and what browsers are in use. If such a feature were to be implemented it would literally require natively hooking into the api of every browser. Something which while can be done would only support the browsers you choose it to (Firefox,Chrome,IE,Safari,Opera) etc etc, but it requires directly interfacing with the native C libraries, something outside of the scope of this and certainly overkill for such a trivial feature.

Download Web Page with Resources using Java

Is there any any api available that capture whole java page just like browser save as option does?
I think emulating a browser in your case might be a easy solution (though a bit heavyweight). Look into HtmlUnit.
you can try and have a look at Lobo : http://lobobrowser.org/java-browser.jsp which is a web-based Java browser. They might provide a way for you to just download a whole page with the resources in a directory.
Another way could be to use something like Selenium and start a Firefox instance in your java app after you recorded a macro for going to File -> Save As ... etc.

Categories

Resources