0

The URL of website is http://www.mca.gov.in/mcafoportal/viewCompanyMasterData.do and when I click the Search icon beside Company/LLP Name it opens an overlay with a text input to enter the company name, but the element is not visible in Selenium Webdriver C# Here's the Screenshot of the wepPage Below is the HTML code for Text Field

<input type="text" size="40" id="searchcompanyname" name="searchcompanyname" onkeydown="javascript: if (event.keyCode==13) return fetchCINData();">

and here's my C# code

IWebDriver chrome = new ChromeDriver("C:\\");
        chrome.Navigate().GoToUrl("http://www.mca.gov.in/mcafoportal/viewCompanyMasterData.do");
        chrome.FindElement(By.XPath(".//*[@id='imgSearchIcon']")).Click();
        bool a = chrome.FindElement(By.CssSelector("input[type=text][name='searchcompanyname']")).Displayed;
        MessageBox.Show(""+a,"");
Gokul
  • 788
  • 2
  • 12
  • 30
Nikhil
  • 21
  • 1
  • 5

1 Answers1

1

When you click the search icon it takes +1 seconds for the form and the search input to get displayed, But in your code you're checking the element right after clicking the search icon which will take just a couple of milliseconds. So you need to wait before doing that, maybe using Thread.Sleep(2000); Or better keep checking if the element is displayed each -maybe- 500 ms.

Ayoub_B
  • 702
  • 7
  • 19
  • `Thread.Sleep()` is [highly discouraged](https://stackoverflow.com/questions/17826651/why-thread-sleep-is-bad-to-use) You should be using explicit or implicit waits for these types of issues. `WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); IWebElement myDynamicElement = wait.Until(d => d.FindElement(By.Id("someDynamicElement")));` is an example. See the webdriver [documentation](http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp) – Kpizzle Sep 06 '17 at 15:31