I'm using selenium C# chrome driver to access some website and download data from it. This is a sample code of my application.
public class HomeController : Controller
{
public ActionResult Index()
{
try
{
AppSettingsReader configReader = new AppSettingsReader();
using (var driver = new ChromeDriver(HostingEnvironment.ApplicationPhysicalPath)) //here I used latest chrome driver(V 2.42.59)
{
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
//driver.Manage().Timeouts().PageLoad = TimeSpan.FromMinutes(2);
driver.Url = "https://crims.crib.lk";
var userNameField = driver.FindElementById("txtUserName");
var userPasswordField = driver.FindElementById("txtPassword");
driver.Quit();
}
}
catch (Exception ex)
{
Logger.LogWriter(" WebApplication2.Controllers", ex, "HomeController", "Index");
}
return View();
}
}
This code is working properly when I execute code through VS. After publishing the application through IIS server, Driver does not navigate to the URL. Following error showing in the log file.
Source :WebApplication2
Module:HomeController
Method:Index
Message :no such element: Unable to locate element:
{"method":"id","selector":"txtUserName"}
(Session info: chrome=69.0.3497.100)
(Driver info: chromedriver=2.42.591088
(7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT
6.2.9200 x86_64)
StackTrace : at
OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response
errorResponse)
This same error occurred in VS when the browser does not navigate to URL properly. How to solve this problem. And keep note I installed following NuGet packages successfully. I'm wroking on windows server 2012 PC. I hosted my app its own IIS
NuGet Packages: RC | WebDriver | WebDriverBackedSelenium | Support
Thanks in advance.