2

Error - Not Visible Exception Was Unhandled Error - 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);

In Java & they do not offer good enough answers:


I get an error message on adding this code:

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

I have added an internal class. But I am getting the error:

"An unhandled exception of type 'System.NotImplementedException' occurred in BBC_W_FCast_New_01.exe Additional information: The method or operation is not implemented."

The error comes from this particular line of code:

throw new NotImplementedException();

Here is the class:

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

}

alecxe
11.4k11 gold badges52 silver badges107 bronze badges
asked May 19, 2017 at 11:56
2
  • Either your locator is wrong or you need to use ExplicitWait, as already answered. Commented May 19, 2017 at 12:48
  • I have used the explicit wait. But I still get errors. I have added an internal class: 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(); } } } Commented May 19, 2017 at 13:19

1 Answer 1

1

I recommend you switch from ImplicitlyWait to Explicitly wait for the element you want as detailed at http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp

Example:

WebDriver driver = new FirefoxDriver();
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
 .until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));
answered May 19, 2017 at 12:10
3
  • I added an explicit Wait. But I get an error message. I have added it above. The information from my research is not clear to be honest. I have tried adding Selenium Wait classes to my project & I get the same error. What are your thoughts, please. Commented May 19, 2017 at 12:40
  • I see the code but not what error message you are getting? Also please consider posing this as additional / separate question rather than changing original. We want the question and answer to be clear and helpful for others that run into the same situation. Commented May 19, 2017 at 12:42
  • The error is: "ElementNotVisible Exception Was Unhandled". I added the question to the one below that which I posted earlier. I actually did not change the original. A screen shot of the error message is the first one at the top of the web page. Thank you very much. Commented May 19, 2017 at 12:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.