Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8357741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:34:40+00:00 2026-06-09T10:34:40+00:00

I have following check in my WebDriver script, where I am pulling a date

  • 0

I have following check in my WebDriver script, where I am pulling a date field out of a page.

IWebElement crInfo = driver.FindElement(By.Id("crInfo"));
string copyDate = crInfo.Text;
// From the converted string now pulling out the year by index and length
string copyYear = copyDate.Substring(2, 4);
// Get the current year
int nowYear = DateTime.Today.Year;
// Converting the year
nowYear.ToString().Trim();
// Make the comparison to be sure the copyright is using the current date
Assert.AreEqual(copyYear,nowYear);

As noted in the snippet what I am trying to do is confirm that the date that appears in the page is the current year, this is just a web front end check that the function put in place is returning the right value. When I run this though what I see in the NUnit console is:

error: Expected: “2012”
But was: 2012

I don’t really get the difference between the two, is the quoted value a string? I added the conversion in my script to be sure that they are the same type and added the trim in case there might be white space.

If I want to make this work, what is it that I am not doing to get the Assetion to pass?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:34:43+00:00Added an answer on June 9, 2026 at 10:34 am

    Look at your types and the assertion:

    string copyYear = ...
    int nowYear = ...
    Assert.AreEqual(copyYear,nowYear);
    

    That assertion will never ever pass, whatever the values are. A string is never equal to an integer in C#. While there are languages which do type coercion in this sort of scenario, C# isn’t one of them.

    Also note that this line is useless:

    nowYear.ToString().Trim();
    

    Strings are immutable in .NET – methods like Trim() don’t change the string they’re called on – they return a new string. You’re ignoring that return value… and anyway, you’re calling it on a string you completely ignore afterwards. You could use:

    string nowYearAsString = nowYear.ToString().Trim();
    Assert.AreEqual(copyYear, nowYearAsString);
    

    … or you could parse copyYear to an int first instead, and compare that instead:

    int copyYearAsInt = int.Parse(copyYear);
    Assert.AreEqual(copyYearAsInt, nowYear);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method to check allowed characters: private boolean checkIfAllCharsAreValid(String test) {
I have the following script to check if a NFS mount is currently mounted
I have the following login check in my page: class LoungeController < ApplicationController before_filter
I have the following code //check out the tags, if it allready exist update
I have following Model t.string name t.date start_at t.date end_at t.datetime created_at t.datetime updated_at
I have following script that is used to check if file exists in remote
I have the following PHP code // Check if the upload is setted if
I have following source. In insertMessage(..), it calls selectMessage to check whether duplicate record
I have the following $_POST function to check if the fields of 'start', 'middle'
I have the following piece of code to check for supported intents. The code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.