button extension in f# canopy - f#

I'm trying to make a general button extension in f# and canopy.
as you know we can click a button like this in canopy
click (//button[contains(text(),'save')])[last()]
But I'm trying to do something like this.
let _button value = sprintf "(//button[contains(text(),'%s')])[last()]" value
let button value = _button value
click button "save"
but this gives This value is not a function and cannot be applied
Any great ideas?
Thanks in advance

button is a function with signature: string -> string
click is a function with signature: string -> something
So, you cannot pass button to click, you should write:
click (button "save")
or
click <| button "save"
Idiomatically, I would rewrite your code as:
let button = sprintf "(//button[contains(text(),'%s')])[last()]"
click (button "save")

Related

How can I like and retwweet with cefsharp?

I am trying to send a like and a retweet command to a twitter page, with cefsharp, but my tries don't work any more until now.
The like button has 'ProfileTweet-actionButton js-actionButton js-actionFavorite' as button class name.
The tweet buutton has 'ProfileTweet-actionButton js-actionButton js-actionRetweet' as classname : that opens a window with a button having 'EdgeButton EdgeButton--primary retweet-action' as class name.
string click = "document.getElementsByClassName('EdgeButton EdgeButton--primary retweet-action')[0].submit();"; //.button();"; //ProfileTweet-actionButton js-actionButton js-actionRetweet
Task<JavascriptResponse> response = browser.EvaluateScriptAsync(click);
click = "document.getElementsByClassName('ProfileTweet-actionButton js-actionButton js-actionFavorite')[0].submit();"; //.button();";
response = browser.EvaluateScriptAsync(click);
gives a {not yet computed} Task.result, and button() instead of submit() methods give the same result.
Perhaps the do-undo buttons add a layer of something, to click on them ?
Tx a lot for your tips/ideas, in all cases.

How do I verify and assert if an animation is playing after clicking a button in XCUITest?

I can't seem to find any information when it comes to animation testing on XCUITest.
The scenario that I am testing is that:
When a button is pressed
Then animation will be displayed on the icon
How do I do this?
I recommend setting a meaningful accessibilityValue on the button when it it's animating, which will let voice over users that something is happening too -- then you can check the value property of the corresponding XCUIElement in your test.
// product code
#IBAction func buttonPressed(_: UIButton) {
self.button.accessibilityIdentifier = "MyButton"
self.button.accessibilityValue = "is animating"
// start animating your button
}
// Test code
let button = self.app.buttons["MyButton"]
button.tap()
XCTAssertEqual(button.value as! String, "is animating")

Button as a Return Key

I have a text field and a button. After the text is inside the text field rather then hitting return, can i hit the button that is near my text field and it will act like the 'return' or 'enter' key.
I have found a stackoverflow anwser, kinda like my question: But still doesn't work "How to click UIButton when user hits return on keyboard"
I just need the button to act like a 'Enter' or 'Return' button.
#IBAction returnButton(sender: UiButton) {
textFieldNextToButton.resignFirstResponder()
}
UPDATE: IN OBJ-C
(IBAction)Button1:(id) sender {
[currentTextField resignFirstResponder];
}

How can I check if a button is pressed during a specific time interval in iOS?

I'm creating a game for iOS and need some help.
Simply put, random letters will be shown in a label(changing at regular interval), and the user must press the button when they recognise a pattern. If they press the button they earn points, and if they miss it, they lose points.
For example:
let's say they are looking for a letter repeating over one gap. They see the letters "R K W K". On the second K they would press the button. I need to be able to check if the button was pressed while that second K was displayed. I have searched here on stack overflow, but I can't really find anything specific to my situation. Thanks in advance for your responses. I'm new here, so I tried to be as specific as possible.
You can do something like this:
Make a global variable of type bool lets call it isMatch.
While displaying other letters make isMatch = false;
When you display the second 'K' (as your example) make isMatch = true
In you button click method check:
if(isMatch){
point++;
}
else point--;
Make sure you change isMatch = false on displaying other letters.
Hope this helps.. :)
As I understood you are displaying K (say) in UILabel and you might be getting input in UITextField, what you should do is implement ValueChanged IBAction for UITextField and add all letters (K, M, X, H) etc in an array what you have on screen for now. When the text changes it will come in above IBAction, match the UITextField's text with the elements of an array. If there is a match, you are done!
Hope this helps!
Just check in the selector for the button ... (If you're using Interface builder replace void with IBAction)
- (void) buttonWasPressed:(UIButton *) sender {
if ([[[sender titleLabel] text] isEqualToString:#"K"])
point ++;
else
point --;
}
try like this
- (void)buttonTapped:(UIButton *)yourbutton;
{
yourbutton.selected = ![yourbutton isSelected];
}
then this
[self.yourbutton isSelected];

UILabel text changing between two strings with each "touch up inside"

I'm learning OBJ.C/Xcode/Cocoa here and have run into a question I can't seem to find an answer for.
I want the text in a UILabel to switch between two states (ON/OFF for example) each time the user clicks the same button.
I can get the label to switch to one state, but can't get it to switch "back" when the user clicks the button again. I am assuming there is some logic required, or checking the status of the object once the button is clicked...
Does this require me to keep track of a bool or the "state" of the Label (or button)?
Would this require two methods to be associated to the button, or can it happen with just one?
Thanks for any guidance/pointing in the right direction/Code snips!!!!
~Steve
I got an answer, and it works:
- (IBAction)flip:(id)sender
{
_flipButton.selected = !_flipButton.selected;
self.flipLabel.text = (_flipButton.selected) ? #"ON" : #"OFF";
}
- (IBAction)flip:(id)sender {
[yourButton setSelected:!yourButton.selected];
self.flipLabel.text = (yourButton.selected) ? #"ON" : #"OFF";
}
This toggles the selected state of the button then checks its state to determine which string to pass to the text property of your label.
the easiest way (I think) is to store a BOOL with the state of the UILabel and (on each click of the button) negate the BOOL and set the appropriate text of the Label
You could call this: yourLabel.enabled = !yourLabel.enabled on button click to change the enabled-state of your UILabel. Or what kind of state do you mean ?

Resources