How to make my robot use an URL response time - java

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.

Related

Selenium WebDriver / Java - Simulate Human Like Cursor Movement

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

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.

onappear in sikuli - java

I am looking for the application of "onappear" along with click, wherein I want to click on the captured GUI once it appears.
I know this can be done using "wait" and then using "click", but then I have to statically feed in the wait time, which I wish to avoid.
Is there a way to use "onappear" and "click" together?
If not can somebody please come up with a solution to wait for a GUI and clicking it thereafter (dynamic wait)?
I can't think of a built-in solution, but you could write your own simple definition to do it. This doesn't use onAppear specifically, but I think it might accomplish your purpose.
In python:
def waitClick(myImage):
time = 0
while time < 30:
if not myRegion.exists(myImage):
wait(.5)
time += 1
else:
click(myImage)
break
This will check every half second for your image to appear, for 15 seconds. When it does appear, it will click the image, and then terminate the loop. Would something like this be helpful?

Is it possible to modify the time OSCeleton sends a lost_user event/message?

I'm playing around with OSCeleton and Processing and succesfully got to track skeletons and do stuff.
What I'm wondering is if there's any way to change the delay time a "lost_user" message is sent to Processing.
This is taking so long for what I'm trying to achive, since i need to stop tracking a user as soon as he goes away from the screen, so I can accept another user's interaction. (imagine an installation where a lot of people wants to play with).
any help/tips would be really appreciated.
Jon
As far as I can tell from the OSCeleton's source and with my minimal experience with the kinect(I never used OSCeleton), there is no way to modify that code to do that. It seems to be a thing handled even lower, by the driver or by the kinect its self(?).
Yet you need not bind yourself with that, and I would suggest a couple of ways to bypass the problem if I understand properly.
First, the latest drivers and examples should have multi-user support, meaning you can just arrange who is your main user. From what I can tell from the source you do get an osc message in Processing when a new user is detected as well as an ID number. You can put each new user that arrives, into an arrayList and figure out a way to do things without depending on the latest user.
If you are still going for the user-after-user thing though, or I was mistaken about the multi-user support(which is mentioned nowhere in the README), you can check yourself whether a user has left the area. Although you can not get a definitive answer like that you can check for example, whether a specific joint or all joints of a user have moved in the last 10-20 osc messages received. That probably means storing the position of this joint in an 10-20 item array and continuously updating while also doing a check on whether the items are different. If all items in the array are the same, your user has not moved a bit and thus probably should not be taken to account.
Last but not least you can switch to other solutions. The one I used about a year ago was "Synapse for Kinect" which also seems stale now. The latest you can use is a Processing library called SimpleOpenNI which definitively have multi-user tracking and you won't need any intermediary programs running to give you the joints.
I hope this helps

Why's Marathon not properly selecting in comboboxes?

I'm using Marthon to run tests on a Java Swing application. I build the base tests by recording, then just make small modifications to the resulting Ruby tests to tweak it to fit what I need. I've run into an interesting problem where comboboxes selections do not work. For example, it'll record...
select("Value", "0.25")
...for the Value combobox, which has a valid option of 0.25 in it. However, during playback, the script pauses execution at that point. If I manually click on the combobox (just to drop it down, not actually selecting anything), then the script will select the right number and continue on.
The problem exists for ALL (so far tested) comboboxes in my application, but none of the other control types. Is there a way to select a value in the combobox that works? I don't mind tweaking the recorded script, I just want to not have to manually click on all my comboboxes each time they're in the script!
Have a look at the object map files for the window and change the recognition properties. That should make this consistent.
The _2 basically means that Marathon is unable to find unique properties to identify the components.
Well, I figured it out already... Apparently the recorder just does a poor job at figuring out the correct label for comboboxes. I was able to get some to work by removing the "_2" or whatever at the end. Others, it took incrementing that number. So, apparently the way the recorder sees the screen layout is different from what the player sees.
edit
The newest version of Marathon appears to have fixed whatever was ailing it before. I'm now unable to duplicate the problem.

Categories