Sikuli click is not effect - automation

I'm using SikulixIDE 1.1.0 to write a script playing Yugioh game (run on Windows 10 x64).
See the main screen:
I start the game manually and then run the script as below:
switchApp("Yu-Gi-Oh! PC")
click("1477213591920.png")
My expectation is that the link named "DUEL MODE" is clicked to go to the next screen. The cursor always moves to that link, but sometimes it works, sometimes does not.
I check the log and see that Sikuli has sent click command but for some reason, the game not accept it. This is the log:
[log] App.focus: [8020:Yu-Gi-Oh!]
[log] CLICK on L(687,488)#S(0)[0,0 1366x768]
I've already tried:
doubleClick instead of click
sleep a few seconds
hover and click
But all do not work, neither.

I would expect that some of the things you have tried will help but if that's not the case you will need to identify whether the button was actually triggered or not. To do that you have to capture the next screen or any part of it that uniquely identifies it. Then you will use it a loop with a predefined number of attempts and some wait time between them and click more than once if the click didn't work. So generally something like that (pseudo code):
attempts = 3
for attempt in attempts:
click(button)
if (nextScreen is available):
break
sleep(time)

I know it's been a while but I ran into a similar problem recently.
The image was found but the click didn't work.
I'm also working on Windows 10 x86_64.
The solution was simply to execute the program as administrator.
Don't know why but now it's working..
I also had to use the double click instead of simple click for some patterns.

In adition to Eugene S Answers, if you are using SikuliX, you can try to Run in Slow Motion. Also, if the image have some effects (like brightness), you can try to use Pattern inside of exists():
if exists(Pattern("DualMode.png").similar(0.6), time_in_seconds):
click(Pattern("DualMode.png").similar(0.6))
By default, the similar() value is 0.8, so if the image have some effect and for example, the color change every second, you can set a lower value between 0 and 1.
PS: Don't forget to put the pattern inside if exists and click, because if you don't put inside of click(), could throw an Image not found error message.

Related

Is there a method for script file loading control in labview?

first, I cannot attach my vi files, sorry. I'm not allowed, but I can attach snippets.
I've got a vi that opens and executes functions from a script file, and I'd like to be able to continuously click a button to reload the script file without having to restart the program. Currently the script file commands sit outside my main while loop and and uses a case statement to put the system in idle mode (manual control) when the button is not depressed before launching the program, or if it is, it will instantly open a dialog box looking for a script file upon program launch. I'd like to be able to open a script file numerous times during the execution of my program, but don't fully understand how, and this may be my own misunderstanding of what's going on with the code if I move it inside the main while loop. how is this best accomplished?
If you put your code outside of the loop, it is only executed once (very important: "dataflow"). You need to put the code into a loop to execute it multiple times.
You can insert the vi-snippet into your vi by drag&drop.
My vi contains two different options. You can change the vi as you need it, my vi is incomplete. I inserted a simple 2D-Array because I'm not sure if the vi you use after building the path is selfmade or given by LabVIEW.
For both options you should let the code run in some kind of state machine and use an Event Structure (I think you already implemented your program this way since you wrote about a main loop).
Version 1:
Everytime you click the button, the event is triggered and the code inside the event structure is executed.
Version 2:
Here you set a boolean if the button is pressed and handle the event with that value.
Since you wrote that you already have a main while loop, this option might be better four you. The first loop would be your main-loop, second one would be the loop in Version 2. You just need to add another case for the script to be loaded in.
VI:
I hope this is helpful for your problem.
Feel free to ask if you need more help or if you have any questions :)

SAP GUI scripting - Button press fails

I am using a macro in an Excel file that runs the SAP GUI. There is a step where, when I click a button in SAP there will be another window that pops up.
For that I have written a code like this:
session.findbyid("wnd[0]/XX/btnXX").press
session.findbyid("wnd[1]/XX/btnXXX").press
There is a button (btnXXX) in the window (wnd[1]). But when I execute this query, I am getting an error object not found for findbyid.
When I keep the break point and execute it, it is throwing error on 2nd line in the above code. I try to pick the activewindow.name and it shows wnd[0] still. Here the issue is wnd[1] is not getting opened.
Does somebody know why the 2nd "button press" doesn't work?
You should be able to replace all mouse clicks with keyboard strokes.
Replace:
session.findbyid("wnd[0]/XX/btnXX").press
With:
session.findById("wnd[0]").sendVKey(N)
Where N is the linked hot-key ID.
To get the exact command, use SAP script recording and only use the keyboard to transition between views and windows. The easiest way to determine how is to hover your mouse over the buttons you would normally click to learn the hot-key then record the hot-key.
Note 1) So far I have found that btn[XX] always maps to sendVKey(XX), but I can't be certain this is always the case.
Note 2) sendVKey always appears to be referenced off the window (wnd[Y]) even if a button is another layer down (/tbar, /usr, etc.).

Move target out of bounds exception

I am writing tests for a web application and all went well until I had to choose an option from a menu and that option displays a drop down list when hovered or clicked. When I click an option from the drop down list, I get the following error:
MoveTargetOutOfBoundsException: Element cannot be scrolled into view
Does anyone know what this error is about and what I should look for in my code?
Selenium version 2.25.0, java version 1.6.0_31
I've been checking some selenium and google groups regarding this issue in older versions https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/EuZ7a6_lB9Q
http://code.google.com/p/selenium/issues/detail?id=3075
http://code.google.com/p/selenium/issues/detail?id=4102
a more recent discussion
Is it a known issue for Selenium 2.25.0 or is there a way to fix it? I recently upgraded to Firefox 15.0 :|
Note: I found a temporary solution until someone magically fixes this...since I can't find where the problem is...
I run the code before that point where it crashes, I put it to sleep for 10 seconds, I manually click the menu and the option from the drop down list, the window I want is displayed and the code continues with actions from that point. It works for now...I hope this will be fixed since I can't believe that I can run a script in Selenium IDE but I can't run my java code in WebDriver ...this is crazy :|
I guess you are trying to click an element from a dropdown.
You should keep in mind, that Selenium helps you replicate exact human behavior. So if the code fails because the element is not visible, it is probably because the element is not visible.
To make it work, you might want to put a click command on the menu before the failing bit of code.
(to replicate the sleep 10 seconds manually click the menu button method you are using)
Once again, if you can show us your code and also the HTML snippet of the Menu section, we can provide an exact solution.
Maybe you're opening new popup window while opening select box.
This may help you:
WebDriver.FindElement(By.Id("someInputBox")).SendKeys("hello");
(IJavaScriptExecutor)WebDriver).ExecuteScript("document.getElementById('windowOpener_Button').click();");
WebDriver.SwitchTo().Window("newDisplayedWindowPopupName"); // continue to test

How can Sikuli be used to wait for a button for a long time, with perhaps some maintenance task in between?

I have a webpage where I am waiting for a button to appear, and when it appears I would like to click it. The button is on a timer and may take as long as an hour to appear. Also, if the button takes longer than a certain length of time to appear, I'd like to move the mouse (otherwise the website will log me out automatically).
So, to wait for a button to appear I devised this Sikuli script:
button = "button.png"
while(1):
if exists(button):
print("found it")
click(button)
break
else:
print("wait longer")
wait(button,30*60)
# do a regular task
print "all done!"
The above does not seem to be functional. If the button is on screen, the script will find it... However, if it has to wait it will simply time out quickly with a FindFailed exception (on the click() even though the button does not exist on screen). I considered writing a handler, but seems like overkill.
What am I doing wrong and what is the best way to wait a long period for a visual event like this?
Some other thoughts for you...
while(1):
wait(Button, 30*60) # This will spinlock for 30 minutes for the button to appear
if exists(Button):
hover(Button) # Debug statement allowing user to see what Sikuli has matched to
click (Button)
else:
mouseMove(Location(50,100))
mouseMove(Location(50,200))
Links:
wait
mouse movement link
Location
Maybe Sikuli recognizes something that looks quite your button, and tries to click it.
If you right click in the IDE your button pattern, you can fine tune the tolerance level for recognition. Try to cut the image exactly around your button and increase the value to be more precise.
I suggest you to read this tutorial
http://doc.sikuli.org/tutorials/surveillance/surveillance.html
and to set up a event handler to manage your button when it appears
http://doc.sikuli.org/region.html#Region.onAppear
http://doc.sikuli.org/region.html#observingvisualeventsinaregion
It is not much code to write.
You can get a nice example with full source code in Sikuli's Blog here
http://sikuli.org/blog/2011/08/15/sikuli-plays-angry-birds-on-google-games/
I think you can just set up your handlers and go with
observe(FOREVER)
If you want sikuli to do stuff while your waiting for an image i would use the onAppear(pic, function) and observe(FOREVER, true) methods this is how it works
event = Sikuli.event
def function(event):
click(yourButton.png)
onAppear(picYourWaitingFor.png, function)
observe(FOREVER, true)
basically what this does is onAppear will continuously scan the screen for picYourWaitingFor.png. sikuli continues execution after words so it's scanning while its working. on the appearance of said pic it will jump to the function you put down as the second parameter of onAppear.
I have this same issue as described. Its not about waiting forever. And Observe won't work either, because that does watch forever. Think about wanting to check for event only for a certain period of time say 60 seconds. If it doesn't occur, move on. This could be happening in a specific series of events. If the image doesn't appear in the 60 seconds, move on to do another series.
wait(image,60)
...will crash after 60 seconds if it doesn't find the image, which isn't what is wanted at all in my case.
So I did something like this:
attempt = 1
count=0
while attempt:
if exists(image):
attempt=0
else:
count=count+1
if count>60:
attempt=0
else:
wait(1)
Probably a better way and doesn't give an exact time, but approach doesn't crash the script.
You could also try: except it.. Should be shorter.

Can I use waitForElementWidth Selenium command independently

I just started playing with Selenium and I ran into an issue. I have a link that toggles a hidden div into view using a scroll transition. I am trying to test this function using selenium and the following steps:
1.click on toggle button
2.wait for open transition to finish
3.click on toggle button again to close
My question is can i use waitForElementWidth command for step number 2 without first storing my width with storeElementWidth? lets say I already know the final width of the div when viewable is 200px. Can i do something like:
command: waitForElementWidth
target: id=mydiv
value: 200
It seems to fail for some reason.
EDIT: I am aware that I can use the Pause command with the amount of time that the transition is set for but I am trying to stay away from set times which might change later.
I actually found the answer to this is yes you can use it independently. What i was doing wrong is that I was entering the value as a string in quotations when i just needed to enter it as simple value.