Reputation: 2594
These results are stable with less than 0.500 s fluctuation.
It takes 16.779 s to run on PhantomJSDriver
It takes 13.991 s to run on ChromeDriver
This is the code that I am running:
//Starts Browser, Hides PhantomJS window and Navigates to Page
var driverService = PhantomJSDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
Browser = new PhantomJSDriver(driverService);
Browser.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(1));
//Navigates to the website
Browser.Navigate().GoToUrl("https://www.aapmegaform.com.au/racing/scratchings-and-conditions.aspx");
var lineElements = Browser.FindElements(By.CssSelector(".tableContentContainerInnerBox>div>table>tbody>tr"));
foreach (var element in lineElements)
{
try
{
Console.WriteLine(element.FindElement(By.CssSelector(".scratchingTitle")).Text);
}
catch
{
}
}
Only 4 of the 29 elements exist.
PhantomsJS throws an "element not found" exception 25 times in the output.
Is it reasonable to expect PhantomJS to run that much longer ?
Upvotes: 0
Views: 72
Reputation: 25596
There's a better way to do this... you are searching for a parent element then grabbing each one looking for a descendant element that may or may not exist. Just change your CSS Selector to get only the elements you want. See the updated code below.
Instead of using var
, you should always use the specific type. It makes the code more readable.
With this code, you shouldn't need the try-catch
so I've removed it. This should be much faster also.
BTW, your implicit wait is set for 1ms. There's really not any point to having a wait that short. By the time it checks if it has expired, it's already expired. Maybe you meant to use 1s instead? You shouldn't need the implicit wait for the code below. I would recommend against using implicit wait in pretty much all cases. I would instead add explicit waits (WebDriverWait
), as needed.
Browser.Navigate().GoToUrl("https://www.aapmegaform.com.au/racing/scratchings-and-conditions.aspx");
IReadOnlyCollection<IWebElement> lineElements = Browser.FindElements(By.CssSelector("h3.scratchingTitle"));
foreach (IWebElement element in lineElements)
{
Console.WriteLine(element.FindElement(By.CssSelector(".scratchingTitle")).Text);
}
Upvotes: 2