Jon Maximys
Jon Maximys

Reputation: 75

Page loads and the item is not found

I test some site. Just only try put some text into input field (near Site URL:). I use selenium. My code throw exception. Please, tell me why?

IWebDriver driver = new FirefoxDriver();
try
{
   driver.Navigate().GoToUrl("http://www.w-global.com/index.php/tools-gadgets/online-sitemap-generator");
   IWebElement url_parse = driver.FindElement(By.Name("inputurl"));
   url_parse.SendKeys("http://test.com");
}
catch (Exception ee)
{
   String s = ee.ToString();
}
finally
{
   driver.Quit();
}

Error:

OpenQA.Selenium.NoSuchElementException: Unable to locate element: {\"method\":\"name\",\"selector\":\"inputurl\"}\r\n in OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs...

Upvotes: 0

Views: 635

Answers (2)

Amey
Amey

Reputation: 8548

Change IWebElement url_parse = driver.FindElement(By.TagName("inputurl")); to IWebElement url_parse = driver.FindElement(By.Name("inputurl"));

UPDATE

Just noticed that the element is inside an iframe.

You need to switch to it before trying to find the element.

driver.SwitchTo().Frame("c-analyzer"); #and then
IWebElement url_parse = driver.FindElement(By.Name("inputurl"));

Upvotes: 2

e1che
e1che

Reputation: 1251

Actually, your inputurl from IWebElement url_parse = driver.FindElement(By.TagName("inputurl")); is wrong because there is no inputurl tag in in the html source.

What i can suggest ?

Try to use this selector instead yours

IWebElement url_parse = driver.findElement(By.cssSelector("div.mfid-v3 input"));

i hope this is that input that you're looking for.

Plus, clear it before writing values in. Because your code will do that into the input:

http://http://test.com

So don't forget to url_parse.clear();

Tell me what's up =)

Upvotes: 0

Related Questions