Is it possible to click somewhere unspecific on a page?
I have the issue that a drop down becomes top level in the dom and all other elements are not visible anymore for cypress. A user probably simply clicks somewhere in order to close the dropdown. However, I fail with cypress. I can only click on the dropdown-element itself and since there are multiple items in the dropdown I have to even select one (not wanted)
I need something for cypress to click on something unspecific like:
root().click
or
cy.get('body div').click
These 2 are not working not even with force: true.
I had a similar issue and I used coordinates according to the Syntax
.click(x, y, options)
So you should be able to get the body and click on position x = 50, y = 50 or some other position outside the dropdown menu
cy.get('body').click(50, 50, { force: true })
If this does not work, you can try negative coordinates
cy.get('{{dropdown-menu-name}}').click(-50, 0, { force: true})
If this still does not work use .mousemove()
cy.get("{{dropdown-menu-name")
.trigger("mousemove", 50, 50)
.trigger("mousedown", {which : 1})
.trigger("mouseup", {which : 1})
but that seems excessive
{edit} 50 is the number of pixels to move. That is just an example. of course. Pick a number of pixels what works for your project.
Based on this example (Option #1) I am creating a fixed column by using 2 TableViews in a SplitPane.
The TableView that shows the other columns (not the fixed one) may get so wide that a ScrollBar is displayed, for which I have to compensate with -fx-padding: 0 0 13px 0; in order to keep the TableRows of both TableViews aligned.
So I have to figure out now whether a ScrollBar is being displayed or not or find a completely different way to ensure the TableRow alignment. The obvious way unfortunately doesn't seem to be working. (The ScrollBar is not null, I just didn't post the code to ensure that)
ScrollBar horizontalScrollBar = (ScrollBar) lookup(".scroll-bar:horizontal");
horizontalScrollBar.visibleProperty().addListener((observable, oldValue, newValue) -> {
System.out.println(newValueobservableScrollBar);
});
For some reason the Listener is not fired when the ScrollBar appears or disappears.
So in order to figure out whether a particular scrollbar is visibile I first had to find it, so I looked up all the scrollbars on that particular table.
Set<Node> scrollBars = itemsTableView.lookupAll(".scroll-bar");
Then filter the set in order to retrieve the specific scrollbar I was looking for (horizontal in my case)
Optional<Node> horizontalScrollBar = scrollBars.stream()
.filter(node ->
((ScrollBar) node).getOrientation().equals(Orientation.HORIZONTAL))
.findAny();
And then attach the listener to the visibility-property of the scrollbar
horizontalScrollBar.ifPresent(node ->
node.visibleProperty().addListener((observable, oldValue, newValue) -> {
if(newValue)
{
columnTableView.setStyle("-fx-padding: 0 0 13px 0;");
} else
{
columnTableView.setStyle("-fx-padding: 0 0 0 0;");
}
})
);
Almost looks kinda simply right? Well, it is, as soon as you have figured out that
lookup(".scroll-bar:horizontal");
does NOT return the horizontal scrollbar but the first (vertical) one. And unless you realize that, your Application will behave kinda mysteriously.
When setting the scrollTop and scrollLeft parameters in Safari 6 simultaneously, only one of both gets executed, scrolling the page only over one axis. This happens both using native JavaScript, jQuery and the jquery.scrollTo plugin.
Example using jQuery's .animate():
$('body').animate({
'scrollLeft': 100,
'scrollTop': 100
}, {
'duration': 500,
'easing': 'swing'
});
I've set up a demo page here: http://nabble.nl/demo/safari6scrollto/
All examples work fine in all major browsers as expected, in Safari 6 only example no. 4, 6 and 7 work.
Somehow, when loading the demo page in an IFRAME (see bottom of demo page), everything works just fine.
Is this a bug in Safari? If so, how to work around this issue? If not, what is causing it and how can this be resolved?
Other related reports:
https://github.com/flesler/jquery.scrollTo/issues/9
http://forum.jquery.com/topic/scrolltop-scrollleft-not-working-in-safari-6
http://bugs.jquery.com/ticket/12588
I needed to get the jquery.scrollTo plugin working on OSX Mountain Lion, and since I couldn't find the specifics on what is causing this behaviour, I put together a rather ugly workaround. It uses window.scrollTo(x, y) in the step function of jQuery's .animate(), which gives no problems in Safari 6:
var left;
$(window).animate({
'pageXOffset': 100,
'pageYOffset': 100
}, {
duration: 500,
easing: 'swing',
step: function(now, fx) {
if (fx.prop == 'pageXOffset') {
left = now;
} else if (fx.prop == 'pageYOffset') {
window.scrollTo(left, now);
}
}
});
Please note that the step function is called for every animated property, for every element the animation is applied on (in our case just 1: window). Hence the intermediate variable to store the current X position in the animation.
It uses the pageXOffset and pageYOffset properties of the window object, so I don't know how suitable this workaround is for animating the scrollLeft and scrollTop properties of non-window objects.
Anyway, it works for scrolling the entire document, which was all I wanted, and does so very smooth in Safari 6, too!
I created a jquery cycle slideshow with next/prev buttons, but in addition to that, I want the slideshow to advance when the image is clicked. I don't know javascript well enough yet to code it myself. Is this possible? Here's what I have so far:
$('#illustration .slides').cycle({
speed: 1,
timeout: 0,
prev: '#illustration .prev',
next: '#illustration .next',
pager: '#illustration-thumbs',
pagerAnchorBuilder: function(idx, slide) {
return '#illustration-thumbs li:eq(' + (idx) + ') a';
}
});
$('#illustration img').cycle('next');
you can use your container for the images as a next button if you add swap your next code you have at the moment to this
next: '#illustration .next, #container_div_name',
Hopefully that should achieve what you are after
I am trying to see if I can make my own simulation loop inside Manipulate as I am not happy with either the Trigger control or using Tasks (both have problems and limitations for what I'd like to do).
So, I was trying to see if I can make my own control loop, this way I have better control of things, where by clicking on a 'run' button, simulation loop will start until a 'stop' button is clicked.
A basic problem is that Manipulate times out after 5 seconds even though I am using SynchronousUpdating -> False. i.e. when I click the 'run' button, I start a loop (with some Pause[] in it of course), and will then update something in the loop. This works fine, but after 5 seconds, the loop stops on its own, since Manipulate decided to time out.
I might be misunderstanding something basic here. I show below simple example:
Manipulate[
Dynamic[Refresh[Text#x,TrackedSymbols->{x}]],
{{x,0},ControlType->None},
{{running,True},ControlType->None},
Button[Text["play"],
{
running=True,
While[running,
x+=1;
FinishDynamic[];
Pause[0.1]
]
}],
Button[Text["stop"],
running=False
],
TrackedSymbols->{None},
SynchronousUpdating->False,
SynchronousInitialization->False
]
When running the above, it always stops around count 58 or so, which is about 5 seconds, the time-out value for Manipulate
Outside Manipulate, it works ok as expected:
x = 0;
Dynamic[Refresh[x, UpdateInterval -> 0.001]]
Do[
(
x += 1;
FinishDynamic[];
Print[x];
Pause[0.01]
), {i, 0, 200}
]
I can make the count above as large as I want, no problem.
So, it seems a configuration option for Manipulate, but I am now not able to find now which option it is I need to use for this to work.
Thanks
Update
Using the Method->"Queued" as given below by Simon, now the loop works. But there are problems with this method: I can not use Mathematica while the Button is running, even with large Pauses in the loop, as it blocks the whole front end. It behaves as if the button is pressed all the time. So, this idea is out of question to use. Well, it was something to try.
btw, this is a good time to mention this, I found that using cell of type 'code' instead of the default 'input' causes many crashes in the kernel. Just tried cell type 'code' and after few clicks on the button, kernel crashed:
So I no longer use cells of type 'code'.
Back to the drawing board.
Update 2: 8/29/11, 6 PM
Using Mathematica 8.0.1, on windows 7, SP1, intel pc, here is the code that crashes it when using "code" cell
Manipulate[
Dynamic[Refresh[Text#x,TrackedSymbols->{x},UpdateInterval->0.005]],
{{x,0},ControlType->None},
{{running,True},ControlType->None},
Button[Text["play"],
{
running=True,
While[running,
x+=1;
FinishDynamic[];
]
},Method->"Queued"],
Button[Text["stop"],
running=False
],
TrackedSymbols->{None},
SynchronousUpdating->False,
SynchronousInitialization->False
]
May be someone can try the above? Had to click on start/stop few times to get it to crash.
I can reproduce this.
Update 9/2/11
on new answer: It looks Simon version (second one below) seems faster on my PC, Mathematica 8.0.1. I started both at the same time, and the Simon version seems to run faster (counter runs faster).
screen shot:
I think that it's actually the Button that is timing out, not the Manipulate.
To quote the Options > Method section of the Button docs,
By default, button functions are evaluated on a preemptive link, which
times out after 5 seconds:
Set the option Method -> "Queued" for the button and everything works as expected.
You might get better results if you let Manipulate control the "looping":
Manipulate[
If[running, x++, x]
, {{x, 0}, ControlType -> None}
, {{running, True}, ControlType -> None}
, Button["play", running = True]
, Button["stop", running = False]
]
I presume that Manipulate is being used here to support further controls within the real application. If not, then DynamicModule would be sufficient.
DynamicModule[{x = 0, running = True}
, Column[
{ Button["play", running = True]
, Button["stop", running = False]
, Dynamic[If[running, x++, x]]
}
]
]
The following example animates a moving disk using this technique:
DynamicModule[{t = 0, running = True}
, Column[
{ Button["play", running = True]
, Button["stop", running = False]
, Dynamic[
If[running, t++, t] /.
t_ :> Graphics[Disk[{Cos[t/10], Sin[t/10]}]
, PlotRange -> {{-3,3},{-3,3}}
, Axes -> True
]
]
}
]
]