-3
driver.FindElement(By.Id("navHHome")).Click();
driver.FindElement(By.LinkText("Canon")).Click();
driver.FindElement(By.Id("searchBrand")).SendKeys("Canon AP" + Keys.Enter);
driver.FindElement(By.Id("pListSearch")).SendKeys("AP 01" + Keys.Enter);

HTML: Druckerzubehör

            <li><a itemprop="url" href="/canon/default.aspx">Canon</a></li>

I am getting an error No SuchElementException was unhandled An unhandled exception of type 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll

Additional information: Unable to locate element: #searchBrand

Could any one tell me if this is rightly coded?

Thanks

Liam
  • 27,717
  • 28
  • 128
  • 190
Gulshan
  • 1
  • 2
  • Please format your code for proper viewing and share the relevant HTML DOM. – undetected Selenium May 08 '17 at 09:58
  • basically my doubt is i want to select a item from dropdown box and then select the items by search – Gulshan May 08 '17 at 10:04
  • Please add the error you see, that will help a lot to help you – Ido Ran May 08 '17 at 10:06
  • Provide more info and update the Question as: 1. What is your exact testing steps? 2. What worked for you? Show code. 3. Where are you stuck? 4. Provide error stacktrace. 5. Provide relevant HTML DOM. – undetected Selenium May 08 '17 at 10:07
  • @Gulshan Update your question, dont put html/errors/code in comments. – Jamiec May 08 '17 at 10:11
  • 6
    Its quite clear: Unable to locate element: #searchBrand and from your HTML snippet there is no element with an id of searchBrand – LDJ May 08 '17 at 10:20
  • Sounds like you are trying to select a `select` option value, which has its particularities. Look [here](http://stackoverflow.com/questions/20138761/how-to-select-a-dropdown-value-in-selenium-webdriver-using-java), may help. – Veverke May 08 '17 at 10:25

1 Answers1

2

this code is looking for an id named "searchBrand":

driver.FindElement(By.Id("searchBrand"))

here is the HTML snippet you posted:

<li><a itemprop="url" href="/canon/default.aspx">Canon</a></li>

Do you see an element there with an id named "searchBrand"? Do you see any id's at all? I certainly don't.

When you search for an element that can't be found, it will throw a NoSuchElementException... that's the way it works.

Corey Goldberg
  • 59,062
  • 28
  • 129
  • 143