This is my first ever post on StackOverflow and i hope i have been able to provide the entire issue in detail. Please do let me know in case i need to provide any other information. Issue Description: I am using a regular breadcrumb that displays my navigation order from one page to the other. The breadcrumb has an id = “divbreadcrumb” in html format.
Eg: If I navigate from Home Page (Home ) to Bookings Page(Bookings), then the navigation is as below:
Home > Bookings
I wish to automate my testing of the breadcrumb and check the breadcrumb text displayed on page versus the actual breadcrumb text it should be. I am trying to achieve that by the use of selenium Webdriver along with ATDD tools namely Specflow/SpecRun and Nunit using the code as mentioned below.
Now,when I try to run the test on my local, it works fine but when i check in the code into TFS and build it, the VS Test Runner fails the build because the it cannot find text from the IwebElement element or it returns the text as String.Empty. Now, the same test, when run on my local machine, works perfectly fine giving the expected test results and the expected values for my Iwebelement (for breadcrumb). Also, the above breadcrumb’s HTML structure is being rendered at the backend, which I can say so because I tried to see HTML it renders using the pagesource property of webdriver at runtime and displayed it in my Exception message.
Also, my back-end HTML code is displayed as:
<div class="breadcrumb" >
<div class="breadcrumb-content" >
<div class="breadcrumb" id="divBreadcrumb" >
<a onclick="some code written here" href="xyz.com">Home</a>
> <a href="LMN.com">Bookings </a>
</div>
</div>
</div>
PFB the code that I have used in my automation script to check the text coming from the breadcrumb on the page:
public void TestingBreadcrumb(int p0)
{
InternetExplorerOptions IEOptions = new InternetExplorerOptions();
IEOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
IEOptions.IgnoreZoomLevel = true;
IEOptions.UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Ignore;
IWebDriver iEDriver = new InternetExplorerDriver(IEOptions);
iEDriver.Manage().Window.Maximize();
iEDriver.Navigate().GoToUrl("http://example.com");
var breadcrumb = iEDriver.FindElement(By.Id("divBreadcrumb")).Text.ToString();
Assert.AreEqual("Home > Bookings ", breadcrumb);
}
The error I get is
[ERROR] Expected string length 18 but was 0. Strings differ at index 0. Expected: "Home > Bookings "
But was: <string.Empty>
-----------^