I am new to RFT and Java coding and I was trying to automate a web based application using IBM-RFT tool with Java. I have to click on a link within my HTML table cell. While playback it was able to click on links for some cells but for some it wasn't and was clicking above or below the hyperlink in the cell. It is able to recognize the link object and print out its properties like ".text", ".href" but while clicking it clicks on blank space within the cell instead of clicking on the link and this happens for some cells only.:(
Is there any better way to handle this? Appreciate anyone's help on this.
TestObject[] tablename = root.find(atDescendant(".class", "Html.TABLE", ".id", table_name), true);
GuiTestObject tablename_obj=(GuiTestObject)tablename[0];
TestObject cellObj = tablename_obj.find(atList(atChild(".class" , "Html.TBODY"),atChild(".class" , "Html.TR",".rowIndex", row),atChild(".class" , "Html.TD",".cellIndex",col)), false)[0];
TestObject cellObjClick = cellObj.find(atDescendant(".class","Html.A"))[0];
((GuiTestObject)cellObjClick).click();
Please help!
I can try to give you some clues. The .click() method calculates the center of the object as the click point. Since you can get the .href property and it is correct, then you know you have the link you want to click on. It could be that somthing about the extent of the object (the rectangle surrounding the object that is used to calculate points within the object) is somehow incorrect coming from the DOM. It could be that the click point calculated does not actually click on any part of the link in the UI. Instead of .click(), you could try using a speciic x, y coordinate for the link object. Note the coordinate is relative to the upper left corner of the object. So you could try .click(atPoint(x,y)), choosing some value (pixels) for the x, y coordinate and see if you have any better luck. You could also try getting the rectangle of the link (the extent) fist to see if that looks correct. I have sometimes used .click(atPoint(1,1)). I'm not sure you can see the rectangle of the object in it's properties, using the object explorer in RFT (you could try this).
I prefer using SelectGuiSubItem like the example below sometimes to click
((SelectGuiSubitemTestObject) textObj).select("<>");
Try that out instead of a click()
Related
Not sure if its due to how the application im automating has its UI set up but what Im trying to do is open up a side drawer that holds a couple table rows. I need to drag a table row into another specific area and drop it there to move it.
So heres an Idea of what the interface looks like:
NOTE: All that whitespace is not a valid area to drop the table row the tablerows are only droppable in a very specific area that becomes visible when the tablerow is right above it.
Im trying to drag the items on the right hand drawer to the left hand side.
When I try to use dragAndDropBy to move to the respective x and y offsets it looks like it doesnt move to the correct location.
I have modified my code now to at least help me see whats wrong and it seems like its not moving to the x coordinate set in my code below:
Actions actions = new Actions(driver);
System.out.println(productArrangement.getLocation());
actions.clickAndHold(productArrangement).moveByOffset(-408, 308).perform();
System.out.println(productArrangement.getLocation());
Thread.sleep(4000);
As you guys can see all this is trying to do at the moment is see where my element is being moved too and logging if the element is actually moving to the respective direction and it seems like its not being moved at the x coordinate and is moving at the wrong Y coordinate(but at least its moving).
here is my console
I would expect the second coordinate log to have moved to the specified offSets I put in but I have gotten similar behavior for all the methods I've tried so far.
Please advise assistance would be greatly appreciated.
Use direct dargAndDrop method like below:
Actions actions = new Actions(driver);
actions.dragAndDropBy(productArrangement,-408, 308).perform();
I have 2 exact same images (pattern, color, size ,everything is same) on the screen and in this case how do I click on Image 1?
Whenever I am using the s.click() function, Sikuli tries to click on Image 1 some times and sometimes on Image 2.
I have tried Pattern and exists but they are also not working as expected.
Pattern imagePatternPath = new Pattern("Image.png").exact();
screen.click(imagePatternPath);
I expect to click on Image 1, but the actual output is sometime it clicks on Image 1 and sometimes on Image 2.
If there are two absolutely similar patterns on the screen, there is no way for Sikuli to distinguish them without some help. You have few options to resolve this problem.
location on the screen
If the patterns appear in known areas on the screen, you can limit the search to the expected area and thus, avoid picking the wrong pattern.
search by proximity
If you have any other objects that appear only next to one of the patterns you are attempting to locate but not the other, you can use them as pivots.
Have a look into Sikuli code, especially into the Region class here. It exposes various options to modify the search area around found patterns. For example:
public Region grow(int range) {
return grow(range, range);
}
Try looking at the patch notes next time, they are very helpful. But here is what I would try:
result = findAll("Image.png")
This will return a List which you can iterate through to click the item you wat so in this case you would click the first item.
We have diagram application which is built using Canvas and GoJS. There are many controls in toolbox and I would like to drag particular element to blank area.
I have tried by actions method but that is not working.
I tried code :
actions.moveToElement(paletteCanvas, palette_node_x, palette_node_y);
actions.clickAndHold();
//Dragging selected node a little bit to make it work.
actions.moveToElement(paletteCanvas, palette_node_x, palette_node_y+50 );
//Now perform the actual move
actions.moveToElement(flowCanvas, diagramOffsetX , diagramOffsetY);
actions.release();
actions.perform();
Also it is hard to find offsets for element. Is there any there way by which I can automate following using selenium :
Drag and Drop any control fro toolbox
Select any particular control from tool box
Any possibility to work by JSexecutor?
These links might be helpful to you:
http://forum.nwoods.com/t/how-to-implement-selenium-test-cases-for-canvas/5195
http://forum.nwoods.com/t/locating-elements-on-canvas-by-selenium-webdriver/5509
http://forum.nwoods.com/t/simulate-selectionadorrnmenttemplate-click-selenium/6134
I am working on a research project.The scenario is this.
I am taking the screenshot of my desktop and then I process it using an API to get the position of a certain text on my Desktop.e.g , say I have the browser open on my desktop and I am on stackoverflow.Now I want to search the position of the logo stackoverflow on the screenshot taken.Then I want to simulate a click on it.I am using Java platform.
Now I have 2 questions:
1)Is there any free API(OCR) which I can use to process the screenshot to fetch text position (or can be done by some trick) and gives good results.
Or Any way you can suggest that I can use (instead of taking screenshot and processing it) to get the position of any text on the screen.
2)How can I simulate the click on the screen using the code by a background program running(I mean I have done it in Swing and other language UIs but this time its different as Now I want to click on the screen.
If I understood you right you want to move your mouse and click on the screen. That not that hard you could use the robot class from Java!
For example:
Robot rob = new Robot();
rob.keyPress( KeyEvent.VK_ENTER );
or what ever, there are so much bottons and movements you could with it. A list of all methods you find here.
And your other question I can't answer. I think there is no API that is able to search a text and give you the position. But what I know is that the robot class is able to capture the screen and put it into a BufferedImage. With it you could compare two pictures.
Maybe you could get use of this but I don't know if it is what you search.
Right now, I'm using Java Swing to create a JEditorPane primarily for its ability to have hyperlinks. I've successfully been able to display links and have them execute behavior upon a click, but I'm running into a few problems with formatting.
How can I set the cursor so that it normally is an arrow, but changes to a text cursor when hovering over text? (In essence, the behavior a cursor has within a web browser). I tried
EditorPane.setCursor(new Cursor(Cursor.TEXT_CURSOR))
but that made it a text cursor everywhere, even when not hovering over text. Right now, hovering over a link shows a pointer hand; I'd like to maintain that functionality as well.
What is the best way to show tooltips or mouseover text when hovering over a link? I tried modifying the title attribute of the link but nothing showed up.
I was trying to implement links to skip down to a subsection of the page, much like http://en.wikipedia.org/wiki/Xkcd#History would take you directly to the History subsection of Wikipedia's xkcd page. How can I do this?
An answer to any of these would be great (and multiple would be awesome xP). Thanks a lot for your help!
As you said one can simply give answers to a single point as well, let me try one by one, here is the answer for your last Point 3
Just provide an id to your tag like this
<h1><a id = "top"></a>First Line</h1>
Now somewhere in the bottom of your page write this :
<p>Return to TOP</p>
Clicking this link, you will reach the above area of the PAGE.
Points 1 & 2 may be addressed using the approach mentioned here. In particular, the view/model conversion methods will let you condition setCursor() and getToolTipText(), respectively.
You can get source from here http://java-sl.com/JEditorPaneStructureTool.html
It shows how to obtain text view bounds. First you get caret position for current mouse poiunter using viewToModel() method. Then go down the Views tree achieving leaf view and calcualte it's bounds. See this http://java-sl.com/tip_view_rectangle.html
If your mouse pointer in the view's rectangle then your mouse over text.
You can check whether the text in caret position is link and show your tooltip.
Use this http://java-sl.com/tip_links_in_editable.html to see how to detect whether mouse is over link.
Point 3.rd is answered by #nIcE cOw