Skip to main content
4 of 7
added 182 characters in body
Michael Durrant
  • 25.2k
  • 3
  • 41
  • 113

Error - No Such Element Exception - when using ImplicityWait

Error - Not Visible Exception Was UnhandledError - No Such Element Exception

Here is the code. I have attached the image of the error message:

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

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));

            //Click on Table button
            driver.FindElement(By.XPath(".//*[@id='hourly']/div[3]/table/tfoot/tr[3]/td[10]")).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);

==============================================================

From my research, the answers I have found have the solution in Java & they do not offer good enough answers:

Selenium Webdriver: No such element exception even though element gets available after waiting for some time

http://stackoverflow.com/questions/20903231/how-to-wait-until-an-element-is-present-in-selenium

=======================================================================13:38

I get an error message on adding this code:

//WebDriver Wait WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("locator")));

  • Would appreciate your assistance. Thank you.

OA345
  • 545
  • 1
  • 10
  • 19