studio
latest
false
Important :
La localisation du contenu nouvellement publié peut prendre 1 à 2 semaines avant d’être disponible.
UiPath logo, featuring letters U and I in white

Guide de l’utilisateur de Studio

Dernière mise à jour 29 mai 2025

Utilisation de projets de bibliothèque importés dans des automatisations codées

Ce tutoriel vous montre comment utiliser les objets de projets de bibliothèque importés dans des automatisations codées. L’exemple montre comment utiliser les éléments et les workflows du référentiel d’objets à partir d’un projet de bibliothèque importé. Le scénario donné consiste à automatiser le site Web de l’Acme, pour remplir une carte de score étudiante et l’ajouter à la base de données.

Prérequis

  • Installez les activités UIAutomation version 23.10.13 ou ultérieure.
    Remarque : nous vous recommandons d’utiliser la dernière version secondaire correspondant à la version majeure avec laquelle vous travaillez. Par exemple, si vous utilisez la version majeure 23.10 des packages d’activités, nous vous recommandons de les mettre à niveau vers la dernière version mineure disponible (23.10.x).
  • Publiez l’exemple de la bibliothèque Acme et installez-le dans le projet sur lequel vous travaillez.

1. Créer le projet de bibliothèque

Créez un projet de bibliothèque pour stocker les éléments d’IU essentiels à l’automatisation de l’application Acme, en particulier pour remplir une carte de score étudiante. De plus, créez un workflow low-code (.xaml) ou codé (.cs) dans le projet de bibliothèque, que vous utiliserez plus tard dans une autre automatisation codée.
  1. Créez un projet de bibliothèque nommé AcmeLibrary.
  2. Capturez tous les éléments d’IU que vous souhaitez utiliser dans les sections Référentiel d’objets (Object Repository) et Descripteurs (Descriptors).
  3. Créez un nouveau Workflow codé à partir du groupe Fichier (File).

    Cette étape est cruciale pour activer l’accès au référentiel d’objets dans une automatisation codée lors de l’importation de la bibliothèque dans un autre projet.

  4. Renommez le Workflow low-code principal en Send message box et ajoutez une activité Zone de message (Message box) avec le texte suivant : « Vous avez ajouté une nouvelle carte de score pour un étudiant d’Acme. »
    Remarque : vous pouvez également recréer l’activité Zone de message (Message Box) en tant que workflow codé, en suivant les étapes décrites dans le tutoriel.
  5. Enregistrez et publiez le projet de bibliothèque dans un flux.

    Vous installerez et utiliserez cette bibliothèque publiée dans un autre projet au sein d’une automatisation codée.

2. Créer l’automatisation codée

Après avoir créé le projet de bibliothèque, installez-le dans un autre projet pour tirer parti de ses ressources réutilisables, y compris les éléments et les workflows du référentiel d’objets, qu’ils soient low-code (.xaml) ou codés (.cs).
Tip: When using UI Automation coded automation APIs, remember that the overloads with IScreenDescriptor or IElementDescriptor are intended to work with Object Repository elements, while the overloads with TargetAnchorableModel are meant for use with native selectors obtained through the UI Explorer. Visit UI Automation coded automation APIs to learn how to leverage selectors with UI Automation coded automation APIs.
  1. À partir du groupe Fichier (File), créez un nouveau Workflow codé (Coded Workflow).
  2. Accédez à Gérer les packages (Manage Packages) et installez le projet de bibliothèque que vous avez précédemment créé.
  3. À partir du groupe Fichier (File), créez un nouveau Workflow.
    1. Nommez le workflow notifyStudentScoreCardAdded.
    2. Accédez au panneau Activités (Activities), puis à la section Installé (Installed).
    3. Recherchez le nom du projet de bibliothèque que vous avez importé (pour cet exemple, AcmeLibrary).
    4. Glissez-déposez l’activité Send message box à l’intérieur de notifyStudentScoreCardAdded.
      Désormais, le notifyStudentScoreCardAdded a le même comportement que le workflow Send message box du projet de bibliothèque importé.
  4. Pour améliorer la lisibilité, vous pouvez définir votre application de référentiel d’objets importée en tant que variable appliquant une instruction using au début de votre workflow. Voici un exemple : using app = <ProjectName>.ObjectRepository.Descriptors.
    Avec cette approche, vous pouvez facilement appeler des descripteurs au format suivant : app.<AppName>.<ScreenName>.<UiElementName>
    Pour cet exemple, nous définissons le Référentiel d’objets Acme comme suit :
    namespace UsingImportedLibraryProjects
    {
        using AcmeApp = AcmeLibrary.ObjectRepository.Descriptors;namespace UsingImportedLibraryProjects
    {
        using AcmeApp = AcmeLibrary.ObjectRepository.Descriptors;
  5. Now you can automate the given scenario within Acme. Start by opening the Acme login screen using the Open coded automation API.
    [Workflow]
            public void Execute()
            {
              // 1.Open the Acme app on the Login screen
              var AcmeLoginScreen = uiAutomation.Open(AcmeApp.Acme.LoginScreen); [Workflow]
            public void Execute()
            {
              // 1.Open the Acme app on the Login screen
              var AcmeLoginScreen = uiAutomation.Open(AcmeApp.Acme.LoginScreen);
  6. Type in the necessary credentials for logging into Acme, using the TypeInto coded automation API.
    // 2.Type in the necessary credentials
             AcmeLoginScreen.TypeInto(AcmeApp.Acme.LoginScreen.Email, "john.doe2023@uipath.com");
             AcmeLoginScreen.TypeInto(AcmeApp.Acme.LoginScreen.Password, "12345678");  // 2.Type in the necessary credentials
             AcmeLoginScreen.TypeInto(AcmeApp.Acme.LoginScreen.Email, "john.doe2023@uipath.com");
             AcmeLoginScreen.TypeInto(AcmeApp.Acme.LoginScreen.Password, "12345678");
  7. Use the Click coded automation API, along with a native selector, to click the Login button.
    // 3.Use a native selector to click the Login button
    AcmeLoginScreen.Click(Target.FromSelector("<webctrl tag='BUTTON' type='submit'/>"));// 3.Use a native selector to click the Login button
    AcmeLoginScreen.Click(Target.FromSelector("<webctrl tag='BUTTON' type='submit'/>"));
  8. The login process takes you to the Dashboard screen in the Acme web application. Therefore, use the Attach coded automation API to focus on the new screen.
    // 4. Focus on the Dashboard screen
    var DashboardScreen = uiAutomation.Attach(AcmeApp.Acme.Dashboard);// 4. Focus on the Dashboard screen
    var DashboardScreen = uiAutomation.Attach(AcmeApp.Acme.Dashboard);
  9. Select the Students entry on the website, using the Click coded automation API.
    // 5. Click the Students entry
    DashboardScreen.Click(AcmeApp.Acme.Dashboard.Students);// 5. Click the Students entry
    DashboardScreen.Click(AcmeApp.Acme.Dashboard.Students);
  10. Select Score card to open the Students - Score Card form, using the Click coded automation API.
    // 6. Click Score card, to start filling in a student score card
    DashboardScreen.Click(AcmeApp.Acme.Dashboard.Students.ScoreCard);// 6. Click Score card, to start filling in a student score card
    DashboardScreen.Click(AcmeApp.Acme.Dashboard.Students.ScoreCard);
  11. Focus on the Students - Score Card screen, using the Attach coded automation API.
    // 7. Focus on the Score Card screen where you fill in the necessary information
    var ScoreCardScreen = uiAutomation.Attach(AcmeApp.Acme.StudentsScoreCard);// 7. Focus on the Score Card screen where you fill in the necessary information
    var ScoreCardScreen = uiAutomation.Attach(AcmeApp.Acme.StudentsScoreCard);
  12. Fill in half of the fields in the Students - Score Card form using the TypeInto coded automation API, and elements from the Object Repository.
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.StudentEmail, "john.doe@uipath.com");
    ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.FirstName, "John");
    ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.LastName, "Doe");
    ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.ParentEmail, "johnny.doe@uipath.com");
    ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.Tuition, "Private");ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.StudentEmail, "john.doe@uipath.com");
    ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.FirstName, "John");
    ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.LastName, "Doe");
    ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.ParentEmail, "johnny.doe@uipath.com");
    ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.Tuition, "Private");
  13. Fill in the rest of the fields in the form using the TypeInto coded automation API in combination with native selectors that you discover through the UI Explorer.
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='mathematics' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='physics' tag='INPUT' />"), "B");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='biology' tag='INPUT' />"), "C");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='chemistry' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='geography' tag='INPUT' />"), "C");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='history' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='english' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='computer Science' tag='INPUT' />"), "C");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='professorComments' tag='INPUT' />"), "The student is doing okay, very hardworking and does its best");ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='mathematics' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='physics' tag='INPUT' />"), "B");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='biology' tag='INPUT' />"), "C");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='chemistry' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='geography' tag='INPUT' />"), "C");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='history' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='english' tag='INPUT' />"), "A");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='computer Science' tag='INPUT' />"), "C");
    ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='professorComments' tag='INPUT' />"), "The student is doing okay, very hardworking and does its best");
  14. Select Add score card details using the Click coded automation API.
    // 10. Click the "Add score card details" button using an Object Repository descriptor
    ScoreCardScreen.Click(AcmeApp.Acme.StudentsScoreCard.AddScoreCardDetailsButton);// 10. Click the "Add score card details" button using an Object Repository descriptor
    ScoreCardScreen.Click(AcmeApp.Acme.StudentsScoreCard.AddScoreCardDetailsButton);
  15. Appelez le workflow que vous avez importé à partir du projet de bibliothèque à l’aide de la méthode RunWorkflow(). Fournissez à la méthode le chemin d’accès du workflow à l’intérieur du projet.
    // 11. Invoke imported workflow from library
    RunWorkflow("notifyStudentScoreCardAdded.xaml");// 11. Invoke imported workflow from library
    RunWorkflow("notifyStudentScoreCardAdded.xaml");
  16. Close the browser tabs you opened to automate the scenario, using the Dispose() coded automation API.
    // 12. Close the applications/browsers you opened, to finish he automation
    ScoreCardScreen.Dispose();// 12. Close the applications/browsers you opened, to finish he automation
    ScoreCardScreen.Dispose();

Exemple de projet

To follow the steps and try out the tutorial yourself, see the following sample project: Using imported library projects in coded automations. The file contains the library project, as well.

Cette page vous a-t-elle été utile ?

Obtenez l'aide dont vous avez besoin
Formation RPA - Cours d'automatisation
Forum de la communauté UiPath
Uipath Logo White