-6

I am writing an RFT script using java.

I wanted to know if there is any way in which we can write a java code in script for searching a particular string in the webpage and recognize that object and then click on it.

Manmita
  • 9
  • 3
  • 1
    What you have tried till now? Can you please post your code? – Abhijeet Dhumal Jul 09 '15 at 07:04
  • 1
    Please [edit] your question with an [MCVE (Minimal Complete Verifiable Example)] (http://stackoverflow.com//help/mcve) or [SSCCE (Short, Self Contained, Correct Example)] (http://sscce.org) – Panther Jul 09 '15 at 07:08
  • Why do you want to click on a string? Is it a link or some other object? If it is a recognizable object, you can use the TestObject.find() method. – Roland Jul 09 '15 at 09:53
  • @Roland : Actually yes it is a link. There are set of links in a list. i want to search specific text of that link and click on it – Manmita Jul 21 '15 at 09:51

1 Answers1

0

To find a test object dynamically, you can use the TestObject.find() method. If you have some object in your object map which is a parent object of the object to find (e.g. a document object), you can use this example:

TestObject[] found = document().find(atDescendant(".text", "your particular string"));
GuiTestObject yourLink = (GuiTestObject)found[0];
yourLink.click();

Alternatively you can get all links on the page and do something with them:

TestObject[] links = document().find(atDescendant(".class", "Html.A"));
for (TestObject link : links)
    if (link.getProperty(".text").toString().equals("your string"))
        ((GuiTestObject)link).click();

You can find more information about the find method in this article on the IBM developerWorks page.

Roland
  • 1,220
  • 1
  • 14
  • 29
  • @Roland- I tried your solution but seems like i need more clarity on this one. Actually I am testing a tool that displays list of work items (IBM's RTC). From among these work items I need to find a specific name of a work item(on a single current page) and click on it. – Manmita Jul 22 '15 at 04:47
  • For eg : http://multimedia.journalism.berkeley.edu/media/upload/tutorials/wp-beyond-basics/links2.png Check this link out.. This is kind of what my application looks like. Now i need to find the name of a specific url in the "url" section and if i find that i want to click on it. Please let me know is there a way i can do it using RFT. – Manmita Jul 22 '15 at 04:59
  • I do not understand why the proposed solution should not work. In your screenshot, what is it what you want to do exactly? What information do you have and what do you want to do? Please give an example with explicit values. – Roland Jul 22 '15 at 09:28