Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using Gravity.Services.Comet.Services;
  8. using Gravity.Services.DataContracts;
  9. using Gravity.Services.DataContracts.Dto;
  10. using Gravity.Services.DataContracts.Dto.Enums;
  11. using OpenQA.Selenium.Interactions;
  12.  
  13. namespace Generic_Crawlers_Solution_Net
  14. {
  15.     class Program
  16.     {
  17.         private static CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
  18.  
  19.         private static CancellationToken cancellationToken = _cancellationTokenSource.Token;
  20.          
  21.         static void Main(string[] args)
  22.         {
  23.             RunAsync(cancellationToken).Wait();
  24.             Thread.Sleep(Timeout.Infinite);
  25.         }
  26.         private static async Task RunAsync(CancellationToken cancellationToken)
  27.         {
  28.             var request = new WebAutomation
  29.             {
  30.                 AuthenticationInformation = new AuthenticationInformation { UserName = "ludlamzgull@gmail.com", Password = "Kikoeludad1!" },
  31.                 EngineConfiguration = new EngineConfiguration { ElementSearchingTimeout = 500, PageLoadTimeout = 60000 },
  32.                 DriverParams = @"{""Platform"":""Chrome"",""DriverSource"":""Local"",""DriverAssemblies"":""Binaries.WebDrivers""}",
  33.                 Actions = new[]
  34.                 {
  35.                     new ActionRule {ActionType = ActionType.GoToUrl, Argument ="http://dutchimports.co.uk" },
  36.                     new ActionRule {ActionType = ActionType.SendKeys, ElementToActOn = "//input[@id='product-search']", Argument = "Christian"},
  37.                     new ActionRule {ActionType = ActionType.Wait, Argument = "5"},
  38.                     new ActionRule {ActionType = ActionType.CloseBrowser}
  39.                 }
  40.             };
  41.  
  42.             while (!cancellationToken.IsCancellationRequested)
  43.             {
  44.                 await Task.Factory.StartNew(() =>
  45.                 {
  46.                     var client = new Orbit();
  47.                     client.RunWebAutomationSequence(request);
  48.  
  49.                 });
  50.                 await Task.Delay(TimeSpan.FromSeconds(5));
  51.  
  52.  
  53.             }
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement