2

enter image description here

Here is my code (at the final stage):

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;

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();

            //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);
        }
    }
}

Screen Shot Error

closed as unclear what you're asking by FDM, IAmMilinPatel, Bharat Mane, alecxe, NarendraC Jun 6 '17 at 6:05

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    This looks like some form of homework question. It might help if you reformulated it more to show which parts you are actually stuck on. Like - can you not work out how to create a WebElement ? – SlightlyKosumi May 15 '17 at 14:37
  • SlightlyKosumi, thank you very much for your prompt response. I have added the code I have been able to write. In the question area above, I have also highlighted where I seem to be stuck. Thank you very much. – OA345 May 15 '17 at 22:21
  • Also, for the place where I am stuck, I cannot use the Id identifier to select/identify 21:00. Instead, I am stuck with an HTML identifier. Your advice will be highly appreciated. Thank you very much. – OA345 May 15 '17 at 22:26
1

This seems like a homework assignment, so I'm not going to give you any code examples, but I can give you some direction.

For each of the elements on the page you want to use, you will have to find them using a locator (id/name/class/xpath) which you can find by right-clicking the element on the page and selecting 'Inspect Element' or something similar.

  • For searching, you will need to input or send values to an element. When a command is loading a page or initiates a dynamic page update, look to use dynamic waits like the following:
  • WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.visibilityOfElementLocated(By.‌​id("locator")));
  • For expanding, you will need to click an element.
  • For obtaining, you will need to find the element and the get the value.
    In this case, I would suggest using xpath since there isn't a better identifier. If you use Chrome, when you inspect the value, right click the value in the Elements tab of the developer tool and click 'Copy' > 'Copy Xpath'. You will also need to click on the next day (again suggest xpath) to find the Pressure for tomorrow.
  • Be sure to assign the needed values to variables so you can use them later(hint: look to get values or get text). Once you have the variables with the times, I believe you can use echo <answer here>
  • Thank you very much for your response.In the Question area, I have added the code I have been able to write. I have also highlighted where I seem to be stuck. Thank you very much. Much appreciated. – OA345 May 15 '17 at 22:22
  • Also, for the place where I am stuck, I cannot use the Id identifier to select/identify 21:00. Instead, I am stuck with an HTML identifier. Your advice will be highly appreciated. Thank you very much. – OA345 May 15 '17 at 22:26
  • I've added some information to my answer. Hope it helps! – Swagin9 May 16 '17 at 0:05
  • 1
    Swagin19, I have edited my code after following your directions... Much, much appreciated. I am just at the final step - of subtracting the numbers and echoing in Selenium. I know I am to use the subtract operator. For example, after declaring the variables, use x-y = Then, use the Echo command. Thanks once again. – OA345 May 16 '17 at 15:46
  • 1
    Swagin9, thanks once again, and, apologies for the delay in responding. I have updated the code (after running a build of the code successfully in MS/Visual Studio. But, I am getting an error message. I would be most grateful if you could take a look, please. Thank you very much! – OA345 May 19 '17 at 11:24

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