Lors de l’édition de scripts dans EveryStep Scripting Tool Desktop, vous pouvez ajouter un code C# personnalisé. Consultez Modèle objet de l’outil de script EveryStep : classes, méthodes, propriétés, etc . pour plus d’informations sur la personnalisation du script EveryStep.

Les scripts qui ont été modifiés avec du code C# personnalisé nécessitent une approbation de notre équipe de support technique avant d’être enregistrés. Chaque fois que vous ajoutez un code C# personnalisé ou modifiez un script qui contient du code C# personnalisé, le script est envoyé automatiquement pour approbation. Notez que l’examen et l’approbation du script peuvent prendre un certain temps.

Voici quelques exemples d’ajout de C# dans un script pour utiliser des instructions conditionnelles et des variables définies de manière aléatoire :

Exemples d’instructions conditionnelles

Interruption de l’exécution du script sur une erreur de validation de contenu

Step (1, "test - https://www.test.com");
tab0 = Tabs.NewTab ();
tab0.GoTo ("https://www.test.com");
if ( !tab0.Text.Contains("<KEYWORD>"))
{
return;
}
Par exemple, pour interrompre le script si le mot clé« Connexion »n’est pas trouvé, ajoutez :
if (!tab0.Text.Contains("Login"))

Fermeture des fenêtres contextuelles conditionnelles, le cas échéant

Les conditions de relecture des scripts peuvent varier en fonction des régions géographiques, de l’heure, etc. Ainsi, certains contenus tels que les pop-ups peuvent être affichés en fonction des conditions pendant que nous rejouons le script. Pour spécifier la manière dont vous souhaitez gérer le contenu conditionnel sur votre site Web cible, ajoutez l’instruction if à votre script EveryStep.

Par exemple, pour fermer une fenêtre contextuelle si elle est affichée sur la page pendant une relecture de script et accéder à une nouvelle page

  1. Enregistrez le script avec la fenêtre contextuelle affichée sur la page.
  2. Alternativement: Si vous avez Xpath pour localiser le bouton « Fermer » sur la page cible, vous pouvez enregistrer le script sans la fenêtre contextuelle.
  3. Ajoutez l’instruction if à l’étape où la fenêtre contextuelle est censée apparaître. Utilisez le bouton « Fermer » Xpath pour spécifier la condition.

Notez que nous utilisons la méthode WaitForElement dans l’expression de test « if » pour attendre que la fenêtre contextuelle soit chargée :

tab0.WaitForElement (TimeSpan timeout, string xpath)
// script_version=3.0; everystep_version=0; date=4/8/2022; Chrome=91.0.4472.77
NetworkFilter.Deny ("https://www.adidas.com/api/chk/customer/baskets?sitePath=us");
Tabs.SetSize (1820, 513);
DMBrowser tab0 = null;
Step (1, "adidas Official Website | adidas US - https://www.adidas.com/us/kids");
tab0 = Tabs.NewTab ();
tab0.GoTo ("https://www.adidas.com/");
tab0.Link ("//A[normalize-space(text())=\"KIDS\"]", "//A[normalize-space()=\"3 STRIPE LIFE\"]/../preceding-sibling::DIV[2]//A[normalize-space()=\"KIDS\"]", "//A[normalize-space()=\"Give Back\"]/../preceding-sibling::DIV[3]//A[normalize-space()=\"KIDS\"]").Click ();
Step (2, "Kids Shoes and Clothing | adidas US - https://www.adidas.com/us/kids");
//Waits for pop-up window with the "Close" button to appear on the page for 5 seconds. 
if (tab0.WaitForElement("5sec".ToDuration (), "//*[@ID=\"modal-root\"]/DIV/DIV/BUTTON", "//BUTTON[@ARIA-LABEL=\"Close\"]"))
{
//If the "Close" button detected, clicks the button to close the pop-up. Otherwise, jumps to the next line.
 tab0.Button ("//*[@ID=\"modal-root\"]/DIV/DIV/BUTTON", "//BUTTON[@ARIA-LABEL=\"Close\"]").Click ();
}
tab0.Span ("//A[normalize-space(@TITLE)=\"SHOP NOW\"]//SPAN[normalize-space()=\"SHOP NOW\"]", "//A[normalize-space(@TITLE)=\"SHOP NOW\"]//SPAN[normalize-space(text())=\"SHOP NOW\"]", "(//SPAN[normalize-space(text())=\"SHOP NOW\"])[1]").Click ();
Step (3, "Kids - Ultraboost 22 | adidas US - https://www.adidas.com/us/kids-ultraboost_22");

Ajouter l’article au panier ou à la liste d’attente si l’article n’est pas disponible

Si… else permet à votre script d’effectuer des actions spécifiques telles que des clics sur des boutons, des vérifications de chekbox, la navigation vers une autre URL, etc. en fonction de la condition spécifiée. Par exemple, vous pouvez enregistrer une transaction « ajouter au panier » et souhaiter que le script ajoute un article au panier ou, s’il est en rupture de stock, à une liste d’attente. Vous pouvez le faire en ajoutant un si… Instruction Else :

  1. Enregistrez la transaction du panier.
  2. Pour spécifier l’expression de test, sélectionnez l’élément qui indique que l’article est en stock, par exemple, le bouton « Acheter maintenant ».
  3. Spécifiez l’instruction « if » après avoir accédé à la page de l’élément à l’aide de tab0. Méthode WaitForElement (TimeSpan timeout, string xpath) avec le bouton « Acheter maintenant » Xpath.
  4. Spécifiez l’action à exécuter si l’élément est disponible en tant qu’instruction « if ». Par exemple, le clic « Acheter maintenant ».
  5. Spécifiez l’action à exécuter si l’article est en rupture de stock (aucun bouton « Acheter maintenant » détecté) comme instruction « else ». Par exemple, cliquez sur « Ajouter à la liste ».

Conseils

Pour spécifier d’autres actions de flux, enregistrez les actions en plus du flux par défaut dans le même script. Utilisez ensuite les lignes associées dans l’instruction « else ».

Consultez l’exemple fourni ci-dessous.

// script_version=3.0; everystep_version=0; date=4/8/2022; Chrome=91.0.4472.77
Tabs.SetSize (1820, 479);
DMBrowser tab0 = null;
Step (1, "International Shopping: Shop Computers that Ship Internationally - https://www.amazon.com/b?node=16225007011");
tab0 = Tabs.NewTab ();
tab0.GoTo ("https://www.amazon.com/b?node=16225007011");
tab0.Image ("//IMG[normalize-space(@ALT)=\"Seagate Portable 2TB External Hard Drive Portable HDD – USB 3.0 for PC, Mac, PlayStation, &amp; Xbox - 1-Year Rescue Service (...\"]", "/HTML/BODY/DIV[1]/DIV[2]/DIV[2]/DIV[1]/DIV[2]/DIV/DIV/DIV[2]/DIV[3]/DIV/DIV/SPAN/A/DIV/IMG").Click ();
Step (2, "Amazon.com: Seagate Portable 2TB External Hard Drive Portable HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox - 1-Year Rescue Service (STGX2000400) : Electronics - https://www.amazon.com/gp/product/handle-buy-box/ref=dp_start-bbf_1_glance");
tab0.Navigating ("https://www.amazon.com/gp/product/handle-buy-box/ref=dp_start-bbf_1_glance");
tab0.Para ("//P[normalize-space()=\"500 GB\"]", "//P[normalize-space(text())=\"500 GB\"]", "//LI[normalize-space(@TITLE)=\"Click to select 500 GB\"]/SPAN/DIV/SPAN/SPAN/SPAN/BUTTON/DIV/DIV[1]/P").Click ();

// Waits for the "Buy Now" button to be loaded on the page for 5 seconds. 
if (tab0.WaitForElement("5sec".ToDuration(), "//INPUT[@ID=\"buy-now-button\"]", "(//SPAN[normalize-space()=\"Buy Now\"])[last()]/..//INPUT[@TYPE=\"submit\"]", "(//SPAN[normalize-space()=\"Buy Now\"])[last()]/..//INPUT"))
{
If the "Buy Now" button detected, clicks the button. Otherwise, the "Buy Now" click is skipped from execution and the "Add to List" click is executed. 
tab0.Button ("//INPUT[@ID=\"buy-now-button\"]", "(//SPAN[normalize-space()=\"Buy Now\"])[last()]/..//INPUT[@TYPE=\"submit\"]", "(//SPAN[normalize-space()=\"Buy Now\"])[last()]/..//INPUT").Click ();
}
//if the "Buy Now" button not detected, finds and clicks "Add to List" button instead.
else
{
  tab0.Link ("//A[normalize-space()=\"Add to List\"]", "//A[normalize-space(text())=\"Add to List\"]", "//A[@NAME=\"submit.add-to-registry.wishlist.unrecognized\"]").Click ();
}
Step (3, "Amazon Sign-In - https://www.amazon.com/ap/signin?openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fgp%2Faw%2Fd%2FB07X3XGG3F&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=usflex&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&");
tab0.Navigating ("https://www.amazon.com/ap/signin?openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fgp%2Faw%2Fd%2FB07X3XGG3F&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=usflex&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&");

Randomisation des données

Randomisation des e-mails pour les processus d’inscription

Pour utiliser des e-mails générés aléatoirement dans le processus d’inscription, vous pouvez déclarer une nouvelle variable avec la valeur générée aléatoirement semblable à la suivante :

string mail = ("test" + Guid.NewGuid().ToString("N") + "@gmail.com");

Utilisez la variable comme paramètre de méthode TypeText pour le champ email, comme indiqué ci-dessous :

tab0.TextField ("//INPUT[@TYPE=\"text\"]", "//INPUT[@ID=\"Contact_Email_Addr\"]", "//INPUT).TypeText (mail.ToString ());
// script_version=3.0; everystep_version=4.0.8108.2121; date=4/8/2022; Chrome=91.0.4472.77
Tabs.SetSize (1768, 816);
DMBrowser tab0 = null;
//Declares the mail variable.
string mail = ("test+" + Guid.NewGuid().ToString("N") + "@gmail.com");
Step (1, "Dotcom-Monitor: Website Monitoring and Performance Testing - https://www.dotcom-monitor.com/");
tab0 = Tabs.NewTab ();
tab0.GoTo ("http://dotcom-monitor.com");
Tabs.SetSize (1768, 623);
tab0.Span ("(//SPAN[normalize-space(text())=\"Free Trial\"])[1]", "(//DIV[@ID=\"jivo-iframe-container\"]/preceding-sibling::DIV[3]//SPAN[normalize-space(text())=\"Free Trial\"])[1]", "(//IFRAME[normalize-space(@TITLE)=\"Jivochat\"]/../preceding-sibling::DIV[3]//SPAN[normalize-space(text())=\"Free Trial\"])[1]").Click ();
Step (2, "Free Trial Sign Up - https://userauth.dotcom-monitor.com/Account/FreeTrialSignUp");
tab0.Navigating ("https://userauth.dotcom-monitor.com/Account/FreeTrialSignUp");
tab0.TextField ("//INPUT[@TYPE=\"text\"]", "//INPUT[@ID=\"Contact_Email_Addr\"]", "//INPUT").Click ();
//Sets the email value to the randomly generated value of the mail variable.
tab0.TextField ("//INPUT[@TYPE=\"text\"]", "//INPUT[@ID=\"Contact_Email_Addr\"]", "//INPUT").TypeText (mail.ToString ());
tab0.Button ("//BUTTON[normalize-space()=\"Start Free Trial\"]", "//BUTTON[normalize-space(text())=\"Start Free Trial\"]", "//BUTTON[@TYPE=\"button\"]").Click ();

Entrée à l’âge de 18 à 12 ans

// script_version=3.0; everystep_version=4.0.5953.25078; date=4/19/2016; IE=11.0.9600.17126
Tabs.ConfigureIEVersion (BrowserMode.IE11, DocumentMode.IE11Emulate);
Tabs.SetSize (1768, 651);
DMBrowser tab0 = null;
Step (1, "The input element - HTML5 tutorial - http://www.html-5-tutorial.com/input-element.php");
tab0 = Tabs.NewTab ();
tab0.GoTo ("http://www.html-5-tutorial.com/input-element.php");

// produces random number in range from 18 to 120
int r = (new Random(DateTime.Now.Second)).Next(18, 121);

tab0.TextField ("//INPUT[@TYPE=\"number\"]", "//INPUT[@NAME=\"age\"]", "//B[normalize-space()=\"Age:\"]/..//INPUT").TypeText (r.ToString());

Choisir au hasard le sexe masculin ou féminin

// script_version=3.0; everystep_version=4.0.5953.25078; date=4/19/2016; IE=11.0.9600.17126

Tabs.ConfigureIEVersion (BrowserMode.IE11, DocumentMode.IE11Emulate);
Tabs.SetSize (1768, 714);
DMBrowser tab0 = null;
Step (1, "visible - http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_radio");
tab0 = Tabs.NewTab ();
tab0.GoTo ("http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_radio");
for (int i = 0; i < 5; i++)

// produces random number in range from 0 to 2

int r = (new Random(DateTime.Now.Second)).Next(0, 3);
if (r == 0)
{
tab0.Frame ("//IFRAME[@ID=\"iframeResult\"]", "//IFRAME").RadioButton ("//INPUT[@VALUE=\"female\"]", "//INPUT[@VALUE=\"other\"]/preceding-sibling::INPUT[1]", "//INPUT[@VALUE=\"male\"]/following-sibling::INPUT[1]").Click ();
}
else if (r == 1)
{
tab0.Frame ("//IFRAME[@ID=\"iframeResult\"]", "//IFRAME").RadioButton ("//INPUT[@VALUE=\"other\"]", "//INPUT[@VALUE=\"female\"]/following-sibling::INPUT[1]", "//INPUT[@VALUE=\"male\"]/following-sibling::INPUT[2]").Click ();
}
else if (r == 2)
{
tab0.Frame ("//IFRAME[@ID=\"iframeResult\"]", "//IFRAME").RadioButton ("//INPUT[@VALUE=\"male\"]", "(//INPUT[@TYPE=\"radio\"])[1]", "(//INPUT[@NAME=\"gender\"])[1]").Click ();
}
Delay("3sec".ToDuration());
}

Sélection d’un article aléatoire dans un catalogue de produits en ligne

Pour créer un script qui sélectionne à plusieurs reprises des éléments aléatoires dans un catalogue en ligne, utilisez l’exemple fourni ci-dessous. Notez qu’il est recommandé d’enregistrer d’abord plusieurs clics sur les éléments pour faciliter la modification ultérieure de l’origine.

// script_version=3.0; everystep_version=4.0.8108.2121; date=4/12/2022; Chrome=91.0.4472.77
Tabs.SetSize (1768, 714);
DMBrowser tab0 = null;
Step (1, "Amazon.com: Jewelry Made in Italy: Clothing, Shoes & Jewelry - https://www.amazon.com/b?node=19219863011&pf_rd_r=ZS16WVQN9RD996FPB6TH&pf_rd_p=0b9330ec-285a-4f51-9e1c-6765ca451c5f&pd_rd_r=3b9e3cf5-d247-4f50-8d15-a6683fa46846&pd_rd_w=uNsg8&pd_rd_wg=xFg13&ref_=pd_gw_unk");
tab0 = Tabs.NewTab ();
tab0.GoTo ("https://www.amazon.com/b?node=19219863011&pf_rd_r=ZS16WVQN9RD996FPB6TH&pf_rd_p=0b9330ec-285a-4f51-9e1c-6765ca451c5f&pd_rd_r=3b9e3cf5-d247-4f50-8d15-a6683fa46846&pd_rd_w=uNsg8&pd_rd_wg=xFg13&ref_=pd_gw_unk");

//Collects all images to count the total number of images in the body and saves them to the body's Attribute
tab0.RunScript("(function(){const imgCount=document.querySelectorAll(\".s-image\").length;document.body.setAttribute(\"data-imgCount\", imgCount);})()");
int count = 0;

//Gets the value of the Attribute 
string countString = tab0.Element("//BODY").GetAttributeValue("data-imgCount");

//If countString parsed successfully then clicks a random image on the page. Otherwise, raises an error. 
if (!int.TryParse(countString, out count)) {
  RaiseError(string.Format("Failed to get elements count: {0}", countString));
} else {
  var rnd = new Random();
  int i = rnd.Next(1, count);

//Clicks the picked image  
  tab0.Image (string.Format ("(//IMG[@CLASS=\"s-image\"])[{0}]", i)).Click ();

//Navigates to the item page
Step (2, string.Format ("Amazon.com: Selected Item {0}", i));

//Waits for the navigation to be finished. The Navigating (string url) argument can be set to a random URL since it is being scripted while the source script recording and not interfered with the script execution logic. However, the specified URL will be presented in the report data. Check report data for network requests to find an actual URL that was used in the related script run.
tab0.Navigating ("https://www.amazon.com/KEZEF-Creations-Sterling-Overlay-Necklace/dp/B008Y357US/ref=lp_19219863011_1_1");

//Navigates back to the main page and repeats the cycle. You can populate the following lines as many times as necessary within your script.
Step (3, "Amazon.com: Jewelry Made in Italy: Clothing, Shoes & Jewelry - https://www.amazon.com/b?node=19219863011&pf_rd_r=ZS16WVQN9RD996FPB6TH&pf_rd_p=0b9330ec-285a-4f51-9e1c-6765ca451c5f&pd_rd_r=3b9e3cf5-d247-4f50-8d15-a6683fa46846&pd_rd_w=uNsg8&pd_rd_wg=xFg13&ref_=pd_gw_unk");
tab0.Back ();
  i = rnd.Next(1, count);
  tab0.Image (string.Format ("(//IMG[@CLASS=\"s-image\"])[{0}]", i)).Click ();
Step (4, string.Format ("Amazon.com: Selected Item {0}", i));
tab0.Navigating ("https://www.amazon.com/Saint-MIchael-Archangel-Medal-Patron/dp/B01G3K6M5C/ref=lp_19219863011_1_3");
Step (5, "Amazon.com: Jewelry Made in Italy: Clothing, Shoes & Jewelry - https://www.amazon.com/b?node=19219863011&pf_rd_r=ZS16WVQN9RD996FPB6TH&pf_rd_p=0b9330ec-285a-4f51-9e1c-6765ca451c5f&pd_rd_r=3b9e3cf5-d247-4f50-8d15-a6683fa46846&pd_rd_w=uNsg8&pd_rd_wg=xFg13&ref_=pd_gw_unk");
tab0.Back ();
}