简体   繁体   English

带有Selenium的C#.NET-MVC应用程序在服务器上部署时不起作用

[英]C# .NET - MVC app with Selenium doesn't work when deployed on Server

I made a login automation application with C# + .NET - MVC. 我使用C#+ .NET-MVC开发了一个登录自动化应用程序。

My application works perfectly on my local computer and saves everything on the database. 我的应用程序可以在本地计算机上完美运行,并将所有内容保存在数据库中。

Once I deployed my application on our local machine, the Index View receives the email and password, sends them to the database and saves them. 一旦将应用程序部署到本地计算机上,索引视图就会收到电子邮件和密码,然后将它们发送到数据库并保存。 The next step firing up a WebDriver (Firefox or Chrome worked on laptop) with Selenium. 下一步,使用Selenium启动WebDriver(在笔记本电脑上运行Firefox或Chrome)。 Here, nothing happens. 在这里,什么都没有发生。 It keeps waiting on the localhost forever and both Chrome and FF timeout after a certain period of time. 一段时间后,它将一直等待本地主机,并且Chrome和FF超时。

    [HttpGet]
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult getInformation()
    {
        email = Request["getEmail"].ToString();
        password = Request["getPassword"].ToString();
        saveLogin();
        return RedirectToAction("gatherer");
    }

    public ActionResult gatherer()
    {
        facebookLogin();
        return null;
    }

    private static void facebookLogin()
    {
        chrome = new FirefoxDriver();
        chrome.Navigate().GoToUrl("http://facebook.com");
        chrome.FindElement(By.Id("email")).SendKeys(email);
        chrome.FindElement(By.Id("pass")).SendKeys(password);
        chrome.FindElement(By.Id("loginbutton")).Click();
    }

This is very simple and it worked on my local computer again. 这非常简单,并且可以在我的本地计算机上再次使用。 But deployed on IIS on the server, it doesn't. 但是没有部署在服务器上的IIS上。 In other words : the webdriver never opens. 换句话说:webdriver永远不会打开。

First you need to change from 首先,您需要从

chrome = new FirefoxDriver();

To

DesiredCapabilities capability = DesiredCapabilities.Firefox();
Uri url = new Uri("http://REMOTE_IP:5050/wd/hub");
IWebDriver chrome = new RemoteWebDriver(url, capability);

Then Download Selenium Standalone server and use command prompt to initiate it using 然后下载Selenium Standalone服务器并使用命令提示符使用以下命令启动它

java -jar C:\selenium-server-standalone-2.24.1.jar -interactive -port 5050

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 keycloak不适用于asp.net MVC5网络应用程序(C#) - keycloak doesn't work with asp.net MVC5 web app (C#) 打开Babel运行.Net C#Process,在部署的网站上不起作用 - Open Babel running .Net C# Process, doesn't work on deployed website Angular 8 - 路由在本地工作,但在生产环境中部署时,路由不起作用 - .NET 核心 C# 后端 - Angular 8 - routing works locally, but when deployed on Production, routes don't work - .NET Core C# backend 在服务器上部署时,带有EF6的SQLite无法正常工作 - Sqlite with EF6 doesn't work when deployed on server C#应用程序无法在XP上运行 - c# app doesn't work on XP C#ASP.NET MVC 2:HTML.ListBox不起作用 - C# ASP.NET MVC 2: HTML.ListBox doesn't work ASP.NET MVC C#Razor SQL 1 of 2几乎相同的更新查询不起作用 - ASP.NET MVC C# Razor SQL 1 of 2 almost identical Update Queries doesn't work 使用 C# 从 ASP.NET Core MVC 中的 URL 解析 JSON 数据不起作用 - Parse JSON data from URL in ASP.NET Core MVC using C# doesn't work 当我尝试使用 XPath 使用 C# Selenium 单击按钮时,它不起作用 - When I try to use XPath to click a button using C# Selenium it doesn't work Selenium C#中的显式等待不起作用。怎么了? - Explicit waits in Selenium C# doesn't work . What is wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM