How to use if in applescript - macos

I'm making a game application in AppleScript. But when I was done it said this "Expected end of line but found ":".". The code I used was
display alert "By taping ok you accept the following rules: Do not hack, do not cheat, edit komponents or download our site to your desktop! If you do not follow these rules you could get banned"
if {button returned:"OK"}
tell application "/Applications/Safari.app"
open location http://www.pipadse.wix.com/games
end tell
Can anyone help?

A couple of things. First, display alert with no buttons parameter will just display an OK button, so there's no real reason to check the result. However, if you still want to, or plan on adding additional buttons, you get the result by saving the display alert return value then testing the button returned property of the value, something like this:
set alertResult to display alert "By tapping OK you accept the following rules: Do not hack, do not cheat, edit components, or download our site to your desktop! If you do not follow these rules you could get banned."
if button returned of alertResult is "OK" then
display alert "OK was pressed"
end if
And finally, if you're using this as some form of DRM, it's pretty weak.

Related

How to handle windows pop up in IE using Ruby

Please help me how to handle this pop ups.
Based on your last question, I assume you are using Watir-Classic (even though you have also listed Watir-Webdriver).
As #orde mentioned in the comments, Watir has an Alert class for handling these types of dialogs. Unfortunately, in terms of clicking buttons, Watir-Classic only has an #ok method defined:
# Press the "OK" button on the JavaScript dialog.
def ok
dialog.button(:value => "OK").click
wait_until_not_exists
end
This will not work for this dialog as there is a "Yes" and "No" button rather than an "OK" button. You will need to duplicate this functionality with the right value.
Note that the dialog is a RAutomation window and no longer Watir specific code. As a result, the button values are not always intuitive - it is not always just the text you see. To get the right values, you should ask the dialog what values it sees:
browser.alert.send(:dialog).buttons.map(&:value)
#=> ["&Yes", "&No"]
We can then make the same calls as the #ok method, but with the correct value:
alert = browser.alert
alert.send(:dialog).button(:value => '&Yes').click
alert.wait_while_present
This code is working fine to handle this type of pop ups:
save_dialog = WIN32OLE.new("AutoItX3.Control") save_dialog.ControlClick("Windows Internet Explorer", "Yes", "[CLASS:Button;INSTANCE:1]")

If statement in QF-test

I am learning QF-test and want to do a simple if statement. If I make a change on this one page it enabled an "Apply" button that I want to click if it becomes enabled.
When I check if the button is enabled this is what appears
Check boolean: enabled (true) [buttonApply=>($client)]
So I want to say something like
if 'buttonApply.enabled'=="true"
Mouse Click [buttonApply=>($client)]
but that doesn't seem to work
Well I emailed QF-test support and got this answer
Set the variable in the field 'Variable for Result'. Let's say 'CompPresence'
When you run the script , the variable 'CompPresence' will be filled with the value 'true' if the button "Apply" is enabled.
You can use the If loop like If '$(CompPresence)'==”true”

System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client

I have a telerik radscheduler. I make appointments on it. To add an appointment I have date boxes and a radeditor. On the radeditor I have entered text like this "my test link". I made the word link as a hyperlink (pointing to some link on the internet). I have a submit buttton that adds the appointment. WOrks fine. I click to edit the appointment.Edit it and now save it and it gives me this exception "System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client ". I put validaterequest="false" and it works,but I am reading it is not safe/correct way. How do i proceed?If you need info,please ask.Thanks
It seems like you pass HTML to a field you later edit with a simple textbox, so such an error is expected. Perhaps where you use a RadEditor to get HTML, you should not.

click_no_wait doesn`t act click

I have some code like this:
content.button(:id,/Submit/).click_no_wait
puts 2
autoit = WIN32OLE.new("AutoItX3.Control")
puts 3
autoit.WinWait "XXXX"
puts 4
autoit.ControlClick "","OK","Button1"
After click the Submit button,a alert box will pop out,and the code after will click OK of that.The function "click" will hang program there so I need to use "click_no_wait".
But as a result,I can get the puts of 3,and the submit button doesn`t been licked.
Why?And what is the best solution?
If you are dealing with javascript popups, see this page: http://watirwebdriver.com/javascript-dialogs/
If the #click_no_wait does not open the dialog, but regular #click will, then it does not work for some reason. I have written a blog post about debugging #click_no_wait problems at http://itreallymatters.net/post/1366392123/debugging-and-improving-watirs-click-no-wait-method#.UMCuJoOgnvA
In short, set $DEBUG to true before #click_no_wait to get more troubleshooting information:
$DEBUG=true
content.button(:id,/Submit/).click_no_wait
$DEBUG=false

intercepting the onload event fired by the browser in watir

I have a unique situation over here. I have a button on a form which produces a popup if there are some errors in the form. [I know this is not good practice, but the developers of the product would not be changing that behavior!] The form navigates to a different page if all the required fields are correctly populated. Now, I need to write a script in order to click the "Submit" button on the form which either might produce a popup or navigate to the next page.
I have the used the click_no_wait on the "Submit" button and handled the popup using AutoIt as per Javascript Popups in Watir. Now, if all the information is valid and the form navigates to the next page, I use a delay in the script by following some of the techniques described in How to wait with Watir. I am using a Watir::wait_until() to wait in the script.
Now sometimes because of some network issues, it takes time to go to the next page (report-generation) page when the form is submitted and thus the script fails because of the timeout value specified in the wait_until.
I was wondering whether there is a way to intercept the onload event of the HTML page in Watir, since the onload event isn't fired until the entire page is loaded. By that way I could have an accurate estimate of the timeout value and not experiment with it. Thus, my script will pass 100% rather than say 98% right now.
Thanks for any help on this topic.
You could try setting up a rescue for the time out, then looping a reasonable amount of times (2 or 3?) if it encounters a timeout.
E.g.
# All your button clicking and autoit stuff here
i = 0
begin
b.wait_until{ # the thing you're waiting to happen }
rescue TheSpecificTimeOutException
# Sorry I can't remember it, the command prompt will tell you exactly
# which one
if i < 3
i += 1
retry
else
raise
end
end
I'm sure i'll have messed something up in the above, or there'll be more concise ways of doing it, but you get the idea. When it times out, give it another few tries before giving up.

Resources