1

I'm trying to subtract the result of 2 variables and I want to echo the result in Selenium.

I'm using VS2015 as my IDE.

//Obtaining pressure For 2100 hours today
driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[16]")).Click();
    
//Obtain pressure for 2200 Hours tomorrow
driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[7]")).Click();
    
//Subtract the two values above and then 'echo' the result in Selenium
int var2 = 1014;
    
var2 - var1 = 

The last part of the code is where I require some assistance, please.

Any ideas?

Here is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium.Support.UI;

namespace BBC_W_FCast_New_01
{
    class Program
    {
        static void Main(string[] args)
        {
            //Instantiate Firefox Driver
            var driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.bbc.co.uk/weather");

            //Using the 'Find a Forecast' search field to get the weather in 'Reading, UK'
            var user = driver.FindElement(By.Id("locator-form-search"));

            //Use "Reading, Reading" to avoid ambiguity. There is a location called Reading in USA
            user.SendKeys("Reading, Reading");

            //Click on Search button
            driver.FindElement(By.Id("locator-form-submit")).Click();

            //WebDriver Wait
            //Trial Code 1 - WebDriverWait wait = new WebDriverWait(driver, 30);
            //Trial Code 2 - wait.until(ExpectedConditions.visibilityOfElementLocated(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[10]")));

            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            IWebElement element = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("detail-table-view")));

            //Click on Table button
            driver.FindElement(By.Id("detail-table-view")).Click();

            //Obtaining pressure For 2100 hours today
            driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[10]")).Click();
                                                     
            //Obtain pressure for 2100 Hours tomorrow
            driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[16]")).Click();

            //Subtract the two values above and then 'echo' the result in Selenium
            int val1 = Int32.Parse(driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[16]")).Text);
            int val2 = Int32.Parse(driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[10]")).Text);

            int difference = val1 - val2;
System.Console.WriteLine("Difference is: " + difference);
        }
    }

    internal class WebDriverWait
    {
        private FirefoxDriver driver;
        private TimeSpan timeSpan;

        public WebDriverWait(FirefoxDriver driver, TimeSpan timeSpan)
        {
            this.driver = driver;
            this.timeSpan = timeSpan;
        }

        internal IWebElement Until(object p)
        {
            throw new NotImplementedException();[![Error - NotImplementedException Was Unhandled][1]][1]

Screenshot of error: enter image description here

1 Answer 1

1

The first two driver.FindElement just click on the cells; probably you would want to query their content as well:

`var cell16 = driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[16]")).Text();`

After that, you would make the subtraction:

var result = cell16 + cell07;

Console.WriteLine(result);

0

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.