Selenium WebDriver / Java - Simulate Human Like Cursor Movement - java

I want to automate a simple task inside Facebook Ads Manager. This task involves setting up a campaign and uploading some ads. It can take a human 30 minutes to do this. However, they're doing the same thing every single time. Often with mistakes. It's something that should be automated. Done without human emotion or mistakes.
Facebook is very sensitive and I don't want it to ban me for the wrong reasons. So I need to feel human. I can take my time between clicks. However, the cursor movement itself needs to feel human. I only need to simulate a real human click for ethical purposes.
Say I get an element I want to move my cursor towards:
WebDriver driver;
// Set file path of chrome driver
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
// Create object
ChromeDriver driver = new ChromeDriver(options);
// Go to URL
driver.get("FACEBOOK URL");
// Get element
driver.findElement(By.xpath("//span[contains(text(), 'Setup Campaign')]");
What is the best way to move my cursor towards this element as a real human would?
A real human would first move the mouse. Not just click the element
They would move the mouse/cursor slowly. It could take up to say 500-1000 milliseconds. Certainly not instantly.
They would move the mouse/cursor in a curved fashion. Not just in a 100% straight line. Possibly, in a random fashion? So some elements of randomness may be needed?
I'm quite new to Selenium, so any input would be greatly appreciated.
I am writing my code in Java :)

WebDriver doesn't use an operating system input; it communicates directly with the browser via http protocol. If you want to simulate communication like a 'real' mouse input you have to use an automation solution that uses operating system based frameworks. In case of Windows you can use e.g.:
https://github.com/FlaUI/FlaUI (read https://github.com/FlaUI/FlaUI/wiki/FAQ to get the knowledge how to configure Chrome to expose web controls for FlaUI)
https://github.com/microsoft/WinAppDriver

I understand that this is not exactly what you asked, but in this case I recommend you to use the Facebook API instead of selenium.
It's more stable than your approach and without the risk of getting banned.
https://developers.facebook.com/docs/marketing-api/reference/v12.0

Related

How to calculate the time interval of promo banner content using selenium

How to calculate the time interval of promo banner content using selenium web driver
Depends on how the promo-banner is implemented.
Several options:
regularly create a screenshot (and verify them against a ground truth)
get the actual content of the banner (assuming its an image) and verify the URL
query the DOM structure (assuming the promo banner vanishes after a while) and check when the element is gone (or no longer visible)
But without any code from you, or even any idea of how the promo-banner is implemented, this task is hard to solve exactly.

How to make my robot use an URL response time

I'm a java beginner and I'm trying to program a robot that will fill a very annoying form for me.
Why is this form annoyin? Imagine I have to insert a thousand different values into this form but it only lets me insert one value at a time. Everytime time I insert each value I have to press an "OK" button and wait for the URL to update (this takes from 1 to 50s) and only so I'm able to insert another one.
To solve the problem I made a robot that uses a 1min delay between each "OK", but this is far from optimal, since when the URL updates in 1s the robot stays useless for a minute. Even worst, if the url takes more than 1min to update my robot is going to fill the form wrongly.
Is there anything I can do to detect when the url has updated and then use this information as the delay to my robot?
Thanks a lot!
One thing you could try is
Robot.getPixelColor(x,y)
which returns the color of a pixel on the screen. You can tell the robot to wait until the pixel is colored "correctly" (which would happen when the page is completely loaded).
You can use Selenium. It provides a good API and lots of tools for you to automate browser work. Some people might argue that this is not the purpose of the library, but I think that in your case it should work. Link: http://www.seleniumhq.org/download/
Why I think this is the solution:
Selenium is a suite of tools specifically for automating web browsers.
Which seems to be just what you are requesting.
P.S. There are third party drivers as well. For instance, you can download a driver for the Chrome browser.

Make GWT application to work even in low bandwidth

I am working on a GWT application, where I want to use files for upload / download based on the internet bandwidth speed.
Is there any way to detect internet bandwidth / speed in GWT to decide which files to be loaded.
Thanks.
You may split your GWT application in parts, so that a part is loaded only when it is required. This is fully documented, see here. Very powerful stuff.
It makes the initial load smaller and faster, no matter what your connection speed is. Each time a new "feature" is used, a small additional package is downloaded (only the first time it is used). This works transparently if you follow the documentation.
Also, make sure you configure the web server properly, so that it makes full use of the cacheability of the GWT *.cache.js parts.
Upload speed can change a few seconds after you have measured it, and then change again and again. And if you try to measure it before loading each file, the overhead of doing it may outweigh any benefits.
If this is critical to your app, you can offer a "full" and "simplified" versions of your app and let users choose. This is an approach used by Chess.com, for example, where connection speed is very important for player experience. Many websites offer a lighter "mobile" version of their apps compared to a more complete "desktop" version, which often means a different resolution for images as well.
Another approach is to allow users to choose between "standard" and "HD" resolutions for media files, but it can be applied to other file types too. This is an approach used by YouTube, iTunes (for movies) and many other websites.
Well, there isn't any thing providing this info, unless you try to download or upload something and measure the time in client side.
Measuring the download bandwidth could be as simple as compute the time you app got loaded, or better send a request to your server to ask for a known size request.
1.- Case 1 (I use gquery for simplicity)
Set this in your index.html
<script>
window._app_start_loading = new Date().getTime();
</script>
Then compute the time your app took
onModuleLoad() {
double start = $(window).prop('_app_start_loading');
double millisecs = start - Duration.currentTimeMillis();
}
And based on the size of your app JS and experience, you could compute whether the user is using a poor quality network.
2.- Case 2: But the example below has a problem, the user browser will cache requests, so it only works the first time the user runs your app. It is much more accurate and realiable to do something like:
onModuleLoad() {
final double start = Duration.currentTimeMillis();
double millisecs = start - Duration.currentTimeMillis();
GQuery.post("my_app/a_fixed_sized_request?" + Duration.currentTimeMillis(), null, new Function() {
public void f() {
double millisecs = start - Duration.currentTimeMillis();
}
});
}
Now you know the size is always the same, and the request is not being cached.
3.- Measuring upload. You can do the same that in case 2, but sending some POST data in the request with a known size. Replace the second parameter.

How to detect a website is a squatter?

I'm trying to detect whether certain websites are "valid" websites. Some things that make a website invalid:
Gives back bad status codes
Page content is empty
Website is a squatter (for example, the url points to a GoDaddy page, or any page that says come register this domain!)
I'm trying to figure out how to detect whether a website is a squatter. I'm using Java if that matters. Any ideas?
Sound like a good task for Machine Learning in my opinion.
Collect a sample of websites, some of them are 'squatters' and some of them are not (this is called the train set).
Use the bag of words model, or the tf-idf model (or any other model) as your features-space, and train a classifier using some supervised learning algorithm (SVM, decision trees,...).
On run time, use your classifier to determine if a website is a squatter or not.
Weka is a java library that implements many Machine Learning algorithm, and might help you.

Implementing a 'Waterfall' simulation in Java

I would like to implement a visualisation of this video in Java as experience to help me understand all of the 'troubles' in creating visualisations. I have some experience in OpenGL, and a good understanding of how to handle the physics involved. However, if anybody knows of any good game engines that may help (or at least do some of the heavy lifting involved in creating a visualisation of the above) I would be grateful.
Also, I noticed that the linked video must use many separate jets in order to operate in the way it does. Is it likely that it was created using something a little lower level such as C? Is it possible to use a higher level language like Java to control such a system?
Honestly, if you want to implement "just that", I think using a game engine is overkill. Just implement a simple particle engine on your own and you are done.
Seriously, that problem is not so difficult, any language can be used for it. The basic principle behind it is the same as behind steam organs or self player pianos. You have an input data that shows what the pattern to play is and you advance it in a given time.
Here is how I would build the basic control system. You take a black and white image. The width is exactly as wide as the number of "emitters" and the length is as long as the pattern needs to be. You read the image and start at the first line. You walk through each pixel in that line and if the pixel is black you emit a drop and if the pixel is white you don't. You then move in a given interval (maybe 25ms) to the next line and set the emitters accordingly.
The cool thing with images is that you can simply paint them in any graphic program. To get the current time to work you render the time into a image buffer in memory, then pass that into the above code. (You even get fonts if you like...)
You can use jMonkeyEngine.
JAVA OPEN GL GAME ENGINE

Categories