1

I am creating an C# / Web Driver automation script that uses a Page Object Framework.

I would like to check certain dollar amounts on a page (premium and tax amounts) and verify that they are correct.

So, what I need to do is:

  1. Read in the premium and tax amount values
  2. Multiply the premium times the tax rate (which is stored in a separate class)
  3. Compare the result with the tax amount that is on the page using an assert statement

Below is the HTML from the page where the premium and tax amounts display.

<tr>
<td class="first-col">Premium:</td>
<td>$805.00</td>
<td>&nbsp;</td>
</tr>
<tr>
<td class="first-col">NJ State Tax:</td>
<td>$40.25</td>
<td>&nbsp;</td>
</tr>

I think I can locate the premium and state tax amounts using the following code

[FindsBy(How = How.XPath, Using = "//td[contains(text(),'Premium')]")]
public IWebElement premium { get; set; }

[FindsBy(How = How.XPath, Using = "//td[contains(text(),'State Tax')]")]
public IWebElement stateTax { get; set; }

However, I am unsure how to retrieve the values and perform the comparison.

Thanks in Advance

1
  • How are you reading the contents from step 1 (premium and tax amounts)? Is the value provided by some external data source (like an excel file) ? Commented Sep 30, 2015 at 3:18

1 Answer 1

1

Your XPaths localize these elements, because these contain the text you've specified:

<td class="first-col">Premium:</td>
<td class="first-col">NJ State Tax:</td>

You want the next td where the actual values are.

In this case, try adding /following-sibling::td, like so:

[FindsBy(How = How.XPath, Using = "//td[contains(text(),'Premium')]/following-sibling::td")]
public IWebElement premium { get; set; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.