Would it be possible to disable a Java program that contains a Robot from running inside of a browser? I don't think so, but I figured I'd ask anyway.
For example, a robot that clicks the the "Ask Question" button on the SO site can be created in Java (based on the pixel location of the "Ask Question" button) using the Robot class. Can somebody alter the stack-overflow website such that said Java program can't run on it?
No, they could alter the site and move the button or add a captcha challenge or something like that, but essentially, to the SO servers a request from your java program looks like any other request.
Web site admins really only have the request URL and the request headers for filtering or blocking traffic. You can't manage requests from java.awt.robot directly; you'll have to look for something else to work with.
Related
I'm learning java and I want to create a some kind of bot that will be doing operations on webpages, suchas clicking buttons filling textboxes etc. My question which library use to do it? I found out this bot works well:
https://github.com/DaveDuck321/SmashIt/blob/master/app/src/main/java/tk/smashr/smashit/KahootHandle.java
But I don't know how it's even done, it uses okhttp library, but it just sends http requests, but how author knew which request he need send to server to do stuff? Is it possible to use just reqest to bot any site or it's better to use something like htmlunit?
I'm learning java and I want to create a some kind of bot that will be doing operations on webpages, suchas clicking buttons filling textboxes etc.
Have a look at Selenium which makes it possible for you to control a web browser through all kinds of programming languages, including Java.
Further reading:
The Selenium ‘click’ command
How to press/click the button using Selenium if the button does not have the Id?
I want to make a simple program that ask you which browser you want to use.
When you'll click on a link (email or pdf for example), a program will appear instead of the browser and will ask you which browser you want to use.
First : in which code it's the best to write this?
Secondly : How to open the program and not the browser?
I need a bit of help to write this, because i don't know how begin
This is tricky. There is no uniform event for "User clicks on url" that spans all applications.
The most straightforward solution would be to create your application and register it as the default browser.
Personally I would be annoyed by having to select a browser each time I click a link so I would probably make a helper application that when it starts remembers the current default browser and then registers the browser selector as the default. And when the helper closes it would restore the default browser.
My Java is quite rusty but I think this should be possible in either language. Maybe a little trickier in Java due to the lack of a dedicated executable for your application.
For C#:
This will open the url in the default browser:
string url = "http://google.com/";
System.Diagnostics.Process.Start(url);
This will open the url in the specified browser:
System.Diagnostics.Process.Start(#"C:\Program Files\Mozilla Firefox\firefox.exe", url);
There will be an error if the browser does not exist.
I am trying to build a program that once a browser is opened and a login window (Let's say for Facebook) is presented, it will enter in my username and password for the site. I am familiar with the Robot class, and this could be used for the technique, however this is a messy solution. Could anyone suggest a way to go about this? Any good classes? Or is it better just to construct an add-on for a browser?
A plugin gives you direct access to a browser's API so it would be the best approach. That's how Roboform does it, you may want to take at look at what they did.
I'm trying to work out on the add to basket script so I could remotely add products to the basket of ASOS from my server.
There was an API a while ago but it got closed. It's not open anymore.
I'm thinking about developing a java bot. However, I'm still hoping for an easier solution.
EDIT: in brief what i want to know is how to simulate in php the "ADD TO BAG" button pressing process that will eventually add the item to the bag.
Your question is pretty vague. That said, if I understand you correctly, you want to emulate an enduser accessing the system from a web-form. You should simply check for the form's action attribute, and do an HTTP POST to that url with the post variables filled in.
Try to look at Selenium source code btw.
I'm also pretty sure that the system uses cookies for login, so don't forget to go to login page->authenticate->grab the cookies->send it back everytime you add something to your 'basket'.
Although I've been programming for a few years I've only really dabbled in the web side of things, it's been more application based for computers up until now. I was wondering, in java for example, what library defined function or self defined function I would use to have a program launch a web browser to a certain site? Also as an extension to this how could I have it find a certain field in the website like a search box for instance (if it wasnt the current target of the cursor) and then populate it with a string and submit it to the server? (maybe this is a kind of find by ID scenario?!)
Also, is there a way to control whethere this is visible or not to the user. What I mean is, if I want to do something as a background task whilst the user carries on using the program, I will want the program to be submitting data to a webpage without the whole visual side of things that would interrupt the user?
This may be basic but like I say, I've never tried my hand at it so perhaps if someone could just provide some rough code outlines I'd really appreciate it.
Many thanks
I think Selenium might be what you are looking for.
Selenium allows you to start a Web browser, launch it to a certain website and interact with it. Also, there is a Java API (and a lot of other languages, by the way) allowing you to control the launched browser from a Java application.
There are some tweaking to do, but you can also launch Selenium in background, using a headless Web browser.
as i understand it you want to submit data to a server via the excisting webinterface?
in that case you need to find out how the URL for the request is build and then make a http-call using the corresponding URL
i advice reading this if it involves a POST submit