Forum Discussion

Oferv's avatar
Oferv
Super Contributor
12 years ago

Is there a way to paste text that was copy using 'select all' into a variable?

Hi,



I need to use 'select all' to select all text in a document copy this text and paste it to new txt file i have created.



how can i do that?



thanks

5 Replies

  • There are lots of ways you can do this, but it's hard to discern exactly which one you might want.  Can you give a little background about what you are trying to do?  Do you have one application open that you've copied from and another you want to paste into?  Could it be as simple as  you need to set focus to the element you're pasting into and emulate a Ctrl-V?
  • Oferv's avatar
    Oferv
    Super Contributor
    Hi Bert,



    I'll describe,i want to perform a text search,i'm basically testing the search for text in document function.our application display the document so what i need to do is take all the display text(NOTE:the text you see is the text TC see because there could be more text related to the document but TC won't see it because it's not in the view,only if you'll scroll down TC will see it but then it won't see the text before it and so on,it's a dynamically created text to make performance better)select random substring from this text and search for the substring in the document.

    right now,in order to get all the text i'm using 'select all' (CTRL+A) and right click on the text and copy.



    i'll be happy to get more reliable way of getting all the text and get a substring out of it.



    Thanks 

  • Hi Ofer,



    You can use the Sys.Clipboard property to retrieve the text from the clipboard. Then, you can write your text to a file or create a file and write the text from the clipboard to it. To check whether a file exists, use the aqFile.Exists method. To create a file, use the aqFile.Create method. To write text to a file, use the aqFileInfo.WriteToTextFile method.



    See the following sample script:



    ...

    //Path to a file

    var PathToFile = "C:\\TempFile.txt";



    //Use this code line to call the PasteFromClipboardExample function

    PasteFromClipboardExample(PathToFile); 

    ...



    //Pastes the text from the clipboard to the specified file

    function PasteFromClipboardExample(PathToFile)

    {

      //Checks whether the file exists

      if (!aqFile.Exists(PathToFile)) {

        //Creates the file 

        if (aqFile.Create(PathToFile) == 0)

          Log.Message("Target file " + PathToFile + " was created.");

        else

          Log.Error("The file was not created.");

      }



      //Writes the text from the clipboard to the file

      if (aqFileSystem.GetFileInfo(PathToFile).WriteToTextFile(Sys.Clipboard, aqFile.ctUTF8) == true)

        Log.Message("The text from the clipboard has been written to file '" + PathToFile + "' successfully.");

      else

        Log.Error("The text from clipboard has not been written to file '" + PathToFile + "'.");   

    }

  • Oferv's avatar
    Oferv
    Super Contributor
    Hi David,



    I have found a way to search the text for specific substring but,how can i make sure the substring has truly been found in the text.i can see it selected but i want a return value to make sure it's truly been found.

    here is the function i'm using:




    //USEUNIT SelectSpecificPage

    //USEUNIT Math





    //Performing text search in a document

    function SearchTextInADocument()

      {

      //Get the number of display documents

      NumberOfDocuments = Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["WPFObject"]("Grid", "", 1)["WPFObject"]("DocumentViewTabControl")["WPFObject"]("ScrollableTabControlScreen")["ChildCount"] - 4

      //Run over each document to perform a text search

      for(i = 1; i <= NumberOfDocuments; i++)

        {

        //Get the document name and click it

        Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["WPFObject"]("Grid", "", 1)["WPFObject"]("DocumentViewTabControl")["WPFObject"]("ScrollableTabControlScreen")["WPFObject"]("TabItem", "", i)["Click"]()    

        //Get document index

        DocumentIndex = Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["WPFObject"]("Grid", "", 1)["WPFObject"]("DocumentViewTabControl")["WPFObject"]("ScrollableTabControlScreen")["WPFObject"]("TabItem", "", i)["WPFControlIndex"]

        //Get the name to drag and drop      

        TabName = Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["WPFObject"]("Grid", "", 1)["WPFObject"]("DocumentViewTabControl")["WPFObject"]("ScrollableTabControlScreen")["WPFObject"]("TabItem", "", i)["Header"]["Title"]["OleValue"]

        Log["Message"]("Clicking document " + TabName)    

    //    //Get all childrens

    //    var Childrens = Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["Grid"]["DocumentViewTabControl"]["ScrollableTabControlScreen"]["DockPanel"]["ContentControl"]["DocumentDialog"]["Grid"]["docViewer"]["DocumentGrid"]["DocumentGridPage1"]["Border"]["DocumentPageView"]["DocumentPageHost"]["FixedPage"]["WPFObject"]("LINK_"  + (DocumentIndex + 1))["WPFObject"]("Canvas", "", 1)["FindAllChildren"]("WPFControlText", "*", 5);    

    //    var Childrens = (new VBArray(Childrens))["toArray"]();

    //    CanvasCount = Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["WPFObject"]("Grid", "", 1)["WPFObject"]("DocumentViewTabControl")["WPFObject"]("ScrollableTabControlScreen")["WPFObject"]("DockPanel", "", 1)["WPFObject"]("ContentControl", "", 1)["WPFObject"]("DocumentDialog", "", 1)["WPFObject"]("Grid", "", 1)["WPFObject"]("docViewer")["WPFObject"]("DocumentGrid")["WPFObject"]("DocumentGridPage", "", 1)["WPFObject"]("Border", "", 1)["WPFObject"]("DocumentPageView", "", 1)["WPFObject"]("DocumentPageHost", "", 1)["WPFObject"]("FixedPage", "", 1)["WPFObject"]("LINK_" + (DocumentIndex + 1))["WPFObject"]("Canvas", "", 1)["ChildCount"]

    //    //Get text peace to search for specific selected document

    //    CanavasToSelect = Math["RandomInt"](1, CanvasCount)

        //Select all the text from the document

        Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["Grid"]["DocumentViewTabControl"]["ScrollableTabControlScreen"]["DockPanel"]["ContentControl"]["DocumentDialog"]["Grid"]["docViewer"]["Keys"]("^a");

        Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["Grid"]["DocumentViewTabControl"]["ScrollableTabControlScreen"]["DockPanel"]["ContentControl"]["DocumentDialog"]["Grid"]["docViewer"]["Keys"]("^c");

    //    //Right click to select copy

    //    Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["Grid"]["DocumentViewTabControl"]["ScrollableTabControlScreen"]["DockPanel"]["ContentControl"]["DocumentDialog"]["Grid"]["docViewer"]["DocumentGrid"]["DocumentGridPage1"]["Border"]["DocumentPageView"]["DocumentPageHost"]["FixedPage"]["ClickR"]();

    //    //Moves the mouse cursor to the menu item specified and then simulates a single click.

    //    Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["Grid"]["DocumentViewTabControl"]["ScrollableTabControlScreen"]["DockPanel"]["ContentControl"]["DocumentDialog"]["Grid"]["docViewer"]["PopupMenu"]["Click"]("Copy");

        //Get all the text display in the document

        Text = Sys["Clipboard"]

        //Get the text lengh

        TextLengh = aqString["GetLength"](Text)

        //Set start position to serahc from

        SearchStartPosition = Math["RandomInt"](1, TextLengh - 100)

        //Get the text to serahc

        TextLenghToSearch = Math["RandomInt"](1, 100)    

        //Get the random sub string

        SubStringToSearch = aqString["SubString"](Text, SearchStartPosition, TextLenghToSearch)

        //Logging the sub string to search

        Log["Message"]("Searching for substring " + SubStringToSearch + ".In document " + TabName)

        //Click the search field

        Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["Grid"]["DocumentViewTabControl"]["ScrollableTabControlScreen"]["DockPanel"]["ContentControl"]["DocumentDialog"]["Grid"]["docViewer"]["FindToolbar"]["FindTextBoxBorder"]["StackPanel"]["FindTextBoxGrid"]["FindTextBox"]["Click"]();

        //Click select all and delete

        Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["Grid"]["DocumentViewTabControl"]["ScrollableTabControlScreen"]["DockPanel"]["ContentControl"]["DocumentDialog"]["Grid"]["docViewer"]["FindToolbar"]["FindTextBoxBorder"]["StackPanel"]["FindTextBoxGrid"]["FindTextBox"]["Keys"]("^a[Del]");     

    //    //DBClick on 'FindTextBox' object.

    //    Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["Grid"]["DocumentViewTabControl"]["ScrollableTabControlScreen"]["DockPanel"]["ContentControl"]["DocumentDialog"]["Grid"]["docViewer"]["FindToolbar"]["FindTextBoxBorder"]["StackPanel"]["FindTextBoxGrid"]["FindTextBox"]["DblClick"]();

        //Enters 'The Text To Search' in the 'FindTextBox' object.

        Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["Grid"]["DocumentViewTabControl"]["ScrollableTabControlScreen"]["DockPanel"]["ContentControl"]["DocumentDialog"]["Grid"]["docViewer"]["FindToolbar"]["FindTextBoxBorder"]["StackPanel"]["FindTextBoxGrid"]["FindTextBox"]["Keys"](SubStringToSearch);

        //Clicks the 'FixedPage' object.    

        Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["Grid"]["DocumentViewTabControl"]["ScrollableTabControlScreen"]["DockPanel"]["ContentControl"]["DocumentDialog"]["Grid"]["docViewer"]["DocumentGrid"]["DocumentGridPage1"]["Border"]["DocumentPageView"]["DocumentPageHost"]["FixedPage"]["Click"](377, 17);

        //Enters '^[Home]' in the 'docViewer' object.

        Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["Grid"]["DocumentViewTabControl"]["ScrollableTabControlScreen"]["DockPanel"]["ContentControl"]["DocumentDialog"]["Grid"]["docViewer"]["Keys"]("^[Home]");

        //Click the 'Find Next' button

        Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["ContentPanel"]["PART_SelectedContentHost"]["Grid"]["DocumentViewTabControl"]["ScrollableTabControlScreen"]["DockPanel"]["ContentControl"]["DocumentDialog"]["Grid"]["docViewer"]["FindToolbar"]["FindTextBoxBorder"]["StackPanel"]["WPFObject"]("FindNextButton")["Click"]()

                   

        }  

      }

  • Hi Ofer,





    As I see, the M0099753 support case you started seems to consider the same question, so let's continue working on it there, because that case contains more information on the text selection task.