Program.cs
4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Support.UI;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace CentralDispatcher
{
class Program
{
private static readonly string titlePageUrl = "https://www.centraldispatch.com/";
private static readonly string userName = "Empo101";
private static readonly string password = "Miamiheat1";
private static readonly string findVehiclesUrl = "https://www.centraldispatch.com/protected/listing-search";
static void Main(string[] args)
{
var location = new Uri(Assembly.GetEntryAssembly().GetName().CodeBase);
var chromedriverPath = new FileInfo(location.AbsolutePath).Directory.ToString();
// using (
var driver = new ChromeDriver(chromedriverPath);
var windowSize = driver.Manage().Window.Size;
// )
// {
driver.Navigate().GoToUrl(titlePageUrl);
// find login button
var loginBtn = driver.FindElementsByClassName("loginBtn").ToArray()
.Where(x => x.Location.X != 0 && x.Location.Y != 0).FirstOrDefault();
loginBtn.Click();
// set user login and password
driver.FindElementById("username").SendKeys(userName);
driver.FindElementById("password").SendKeys(password);
// find login buttons array
var submit = driver.FindElement(By.XPath("//button[@type='submit'][text()='Login']"));
submit.Click();
// push for authorization button
var exp = driver.FindElementsByClassName("loginBtn").ToArray();
// redirect to find vehicles page
driver.Navigate().GoToUrl(findVehiclesUrl);
var originRegionTypeSelector = driver.FindElementById("originRegionTypeSelector");
originRegionTypeSelector.Click();
var destinationRegionTypeSelector = driver.FindElementById("destinationRegionTypeSelector");
destinationRegionTypeSelector.Click();
// find area originRegion
var originRegion = driver.FindElementByName("origin[region]");
var selectOriginRegionElementAll = new SelectElement(originRegion);
selectOriginRegionElementAll.SelectByValue("All");
// find region area destinationRegion
var destinationRegion = driver.FindElementByName("destination[region]");
// select "All" item
var selectDestinationRegionElementAll = new SelectElement(destinationRegion);
selectDestinationRegionElementAll.SelectByValue("All");
// open area date and pricing options
var dateAndPricingOptions = driver.FindElementById("page-date-pricing-chev");
dateAndPricingOptions.Click();
// open list "readyToShip" items
driver.Manage().Window.Size = new System.Drawing.Size(100, 900);
var readyToShip = driver.FindElementById("readyToShip");
readyToShip.Click();
driver.Manage().Window.Size = new System.Drawing.Size(windowSize.Width, windowSize.Height);
// open list "paymentType" items
var paymentType = driver.FindElementById("paymentType");
var paymentTypeAll = new SelectElement(paymentType);
var optionTypeAll = paymentTypeAll.Options.Where(x => x.Text == "All").First();
optionTypeAll.Click();
var readyToShipWithin = new SelectElement(readyToShip);
var optionReadyToShipWithin = readyToShipWithin.Options.Where(x => x.Text == "14 Days").First();
optionReadyToShipWithin.Click();
// open area date and pricing options
var pageResultOptions = driver.FindElementById("page-results-options-chev");
pageResultOptions.Click();
// open area cargo options
driver.Manage().Window.Size = new System.Drawing.Size(100, 900);
var vehicleOptions = driver.FindElementById("page-vehicle-spec-chev");
vehicleOptions.Click();
driver.Manage().Window.Size = new System.Drawing.Size(windowSize.Width, windowSize.Height);
var btnSearch = driver.FindElementById("btnSearch");
btnSearch.Click();
var body_html = driver.PageSource;
// }
}
}
}