I am writing an IT test in selenium to click on a button that appears only when we hover over another button. Attached recording
I have the below function, but for some reason, it is not hovering. The function is wrapped in a java method.
function moveNodeCenter(canvasParent, nodeIndex){
var canvas = go.Diagram.fromDiv(canvasParent);
var nodeDataArray = getAllNodes(canvasParent);
var targetNodeKey = nodeDataArray[nodeIndex].key;
var targetNodeObj = canvas.findNodeForKey(targetNodeKey);
var robot = new Robot(canvas);
robotMove(robot,targetNodeObj.x,targetNodeObj.y);
}
public void moveNodeCenter(int nodeIndex) throws IOException, InterruptedException {
WebElement canvasParent = this.getCanvasParent();
String script = ResourceUtilities.getResource(DESIGNER_SCRIPT_PATH);
script += "\n moveNodeCenter(arguments[0], arguments[1])";
js.executeScript(script, canvasParent, nodeIndex);
}
can someone help? or is there any away i could do this.
i do see mouseMove event here: https://gojs.net/latest/extensions/Robot.js
Related
I am automating an application which is built with HTML5 using Selenium Webdriver. Now I want to highlight the point I have clicked. Highlighting the element is not a big deal but to know at what coordinates it has been clicked is what I need. For ex. I am clicking an Canvas element at coordinates 200,500.
If I implement java script to highlight element then it will highlight whole Canvas element where as I want to highlight the point(200,500) clicked. Please provide your answers. Thanks in advance.
I am using specflow with C#.
Code for clicking the Canvas at coordinates:
public void ClickCanvasElement(IWebDriver driver, By locator, int offsetX, int offsetY)
{
try
{
IWebElement element = FindElement(driver, locator);
Actions actions = new Actions(driver);
for (int i = 0; i < 10; i++)
{
if ((element.Displayed == true && element.Enabled == true) || element == null)
{
actions.MoveToElement(element, offsetX, offsetY).Click().Perform();
break;
}
System.Threading.Thread.Sleep(500);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
You can try below code:- You need to use javascript to highlight particular element.
public void ClickCanvasElement(IWebDriver driver, By locator, int offsetX, int offsetY)
{
try
{
IWebElement element = FindElement(driver, locator);
Actions actions = new Actions(driver);
for (int i = 0; i < 10; i++)
{
if ((element.Displayed == true && element.Enabled == true) || element == null)
{
actions.MoveToElement(element, offsetX, offsetY).Click().Perform();
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("arguments[0].setAttribute('style', arguments[1]);"element","color: red; border: 3px solid red;");
break;
}
System.Threading.Thread.Sleep(500);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
The only solution what comes to my mind is to edit canvas itself, for example drawing a square/circle with x,y parameters(200,500) as first two arguments in context.fillRect. You could try this approach:
IWebElement element = FindElement(driver, locator);
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("var example = arguments[0]
var context = example.getContext('2d')
context.fillRect(200,500,10,10)",element);
However It will only works If provided by You coordinates are canvas coordinate. If not You will need to take more complicated path (Hope will help: http://javascript.info/coordinates)
Find canvas element
Extract absolute coords of founded element
Calculate relative coordinations
Use javascript for creating new shape on Canvas from point 1
I have the following problem, I need to disable the native Keyboard completely. The keyboard should only show when I call the show() and hide when I call the close() function (this will be on a Button for the user to toggle the Keyboard).
The Keyboard showing on clicking the Field and on Focus needs to be completely disabled.
On Stackoverflow I found this:
InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(editText.getWindowToken(), 0);
So my thought was In the "Init"(Line 52 in the IonicKeyboard.java) I need to change it.
if ("init".equals(action)) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
//new Logic on init
View v = cordova.getActivity().getCurrentFocus();
((InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(v.getWindowToken(), 0);
DisplayMetrics dm = new DisplayMetrics();
cordova.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
final float density = dm.density;
//http://stackoverflow.com/a/4737265/1091751 detect if keyboard is showing
final View rootView = cordova.getActivity().getWindow().getDecorView().findViewById(android.R.id.content).getRootView();
OnGlobalLayoutListener list = new OnGlobalLayoutListener() {
int previousHeightDiff = 0;
#Override
public void onGlobalLayout() {
Rect r = new Rect();
//r will be populated with the coordinates of your view that area still visible.
rootView.getWindowVisibleDisplayFrame(r);
PluginResult result;
int heightDiff = rootView.getRootView().getHeight() - r.bottom;
int pixelHeightDiff = (int)(heightDiff / density);
if (pixelHeightDiff > 100 && pixelHeightDiff != previousHeightDiff) { // if more than 100 pixels, its probably a keyboard...
String msg = "S" + Integer.toString(pixelHeightDiff);
result = new PluginResult(PluginResult.Status.OK, msg);
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
}
else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelHeightDiff ) > 100 ){
String msg = "H";
result = new PluginResult(PluginResult.Status.OK, msg);
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
}
previousHeightDiff = pixelHeightDiff;
}
};
rootView.getViewTreeObserver().addOnGlobalLayoutListener(list);
PluginResult dataResult = new PluginResult(PluginResult.Status.OK);
dataResult.setKeepCallback(true);
callbackContext.sendPluginResult(dataResult);
}
});
return true;
}
return false; // Returning false results in a "MethodNotFound" error.
}
Sadly this does not work at all...
I think I have to change the close / show function too but I am not really sure what the correct code is, and I dont know if this change would affect other Keyboard behaviour. (But I basically need Focus without Keyboard)
I also found this Cordova Plugin
which looks very promising, but I decided to change this in the Ionic Keyboard Plugin, because I need the same behaviour in Windows too.
Very glad if someone could help me out here.
Regards Christopher
This can be accomplished by disabling all inputs with ng-disabled and later showing the keyboard with the Ionic Keyboard Plugin.
If you do not want the inputs to appear differently when disabled, you can override this style with CSS using the :disabled selector.
Hide on load:
<input ng-disabled="hideKeyboard">
hideKeyboard = true;
Show on function:
<input ng-disabled="hideKeyboard">
function showKeyboard(){
hideKeyboard = false;
cordova.plugins.Keyboard.show();
}
How can i invoke right/middle mouse click on web browser
I'm try for simulate right click on a link in web browser with javascript and using from this code for simulation right click but all not work!
HtmlElementCollection links = webBrowser1.Document.GetElementsByTagName("A");
foreach (HtmlElement link in links)
object[] args = { link };
HtmlElement script1 = webBrowser1.Document.CreateElement("script");
HtmlElement script2 = webBrowser1.Document.CreateElement("script");
HtmlElement script3 = webBrowser1.Document.CreateElement("script");
HtmlElement script4 = webBrowser1.Document.CreateElement("script");
script1.SetAttribute("rightc1", "function rightc1(thiselements)
{var element = thiselements;var e = element.ownerDocument.createEvent('MouseEvents');
e.initMouseEvent('contextmenu', true, true,element.ownerDocument.defaultView,
1, 0, 0, 0, 0, false,false, false, false,2, null);
return !element.dispatchEvent(e);}");
script2.SetAttribute("rightc2", "function rightc2(thiselements){$('#thiselements').trigger({type: 'mousedown',which: 3});}");
script3.SetAttribute("rightc3", "function rightc3(thiselements){$('#thiselements').trigger({type: 'mouseup',which: 3});}");
script4.SetAttribute("rightc4", "function rightc4(thiselements)
{$('#thiselements').trigger({type: 'mousedown',which: 3}).
trigger({type: 'mouseup',which: 3});}");
link.AppendChild(script1);
webBrowser1.Document.InvokeScript("rightc1", args);
link.AppendChild(script2);
webBrowser1.Document.InvokeScript("rightc2", args);
link.AppendChild(script3);
webBrowser1.Document.InvokeScript("rightc3", args);
link.AppendChild(script4);
webBrowser1.Document.InvokeScript("rightc4", args);
also i know i can simulate left click with these code link.InvokeMember("Click");
but i want right click and i don't know how can i simulate that.
also i dont want to move mouse and simulate click.
I am required to call a method when mouse hovers onto a RichCommandButton programmatically.
private UIComponent ImageButton(UIComponent parent){
RichCommandButton img = new RichCommandButton();
String imagestyle = "width:120pt; height:120.0pt;margin:10.0pt;";
img.setInlineStyle(imagestyle);
ClientListenerSet set = img.getClientListeners();
if (set == null) {
set = new ClientListenerSet();
}
set.addListener("click", "handle");
img.setClientListeners(set);
parent.getChildren().add(img);
AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
adfFacesContext.addPartialTarget(parent);
return img;
}
and in my JSPX page,
<f:facet name="metaContainer">
<af:resource type="javascript">
function handle(evt){
var source = evt.getSource();
AdfLogger.LOGGER.logMessage(AdfLogger.SEVERE, 'gangangan');
evt.cancel();
}
</af:resource>
</f:facet>
It never goes into this function (checked For log message in console on Chrome->Inspect element). Please let me know how I can invoke a method by mouseOver.
Do you use img.setClientComponent(true) in your method? If your JavaScript needs this component then it needs to be present on the client side too.
I think you should add your client listener to the mouseOver event instead of click:
set.addListener("mouseOver", "handle");
You can check the rest of the available client events in this page.
This should be simple, but for reason I can't quite fathom it doesn't work and - more importantly - I can't find the right question to ask of Google!
What I want to do is prototype an event binder for a JS class as per below, what actually happens is nothing, unless I call .bind() directly on the box object.
function Box()
{
this.Width = 200;
this.Height = 200;
this.WrapperClass = "boxWrapper";
this.TitleClass = "boxTitle";
this.ContentClass = "boxContents";
this.Title = "This is a box";
this.Content = "This is some box contents";
}
Box.prototype.Html = function()
{
var box = $('<div></div>').addClass(this.WrapperClass);
box.append($("<div></div>").addClass(this.TitleClass).append(this.Title));
box.append($("<div></div>").addClass(this.ContentClass).append(this.Content));
box.width(this.Width);
box.height(this.Height);
return box.outerHTML();
}
Box.prototype.Bind = function(event, eventDelegate)
{
this.bind(event, eventDelegate);
}
function clickDelegate(message)
{
alert(message);
}
$(document.ready(function() {
var box = $(new Box().Html());
box.Bind('click', clickDelegate('text'));
$('body').append(box);
}
You have to append box before binding events.
I have created a little fiddle starting with your code and debugging it.
FYI : jQuery object has no method outerHTML, So I've embedded the newly created div in one other.
I've made several changes to your code that's why I'm not posting it here.