【问题标题】:Selenium Webdriver, C# output to console after opening driverSelenium Webdriver,打开驱动程序后C#输出到控制台
【发布时间】:2012-09-06 08:23:33
【问题描述】:

您好,我是第一次使用 Selenium,我正在执行以下代码。它运行良好,但在打开 Firefox 后它不会输出到控制台,因为代码说它应该在代码中的所有步骤完成后执行所有操作。

所以我的问题是如何在实际运行步骤时将该文本输出到控制台?

        var ProxyIP = "xxx.xxx.xx.xxx:80";

        RtbConsole.AppendText("Setting Up Firefox\n");

        //Firefox driver + proxy setup
        FirefoxProfile profile = new FirefoxProfile();
        String PROXY = ProxyIP;
        OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
        proxy.HttpProxy = PROXY;
        proxy.FtpProxy = PROXY;
        proxy.SslProxy = PROXY;
        profile.SetProxyPreferences(proxy);

        RtbConsole.AppendText("Launching Firefox\n");
        FirefoxDriver driver = new FirefoxDriver(profile);

        RtbConsole.AppendText("Navigating to http://whatsmyip.net/ \n");
        driver.Navigate().GoToUrl("http://whatsmyip.net/");


        IWebElement ip = driver.FindElement(By.XPath("/html/body/div/div/h1/span"));
        var myIP = ip.Text;

        RtbConsole.AppendText("Checking IP for Proxy\n");
        if (ProxyIP == myIP + ":80") {
            RtbConsole.AppendText("Proxy Test: Success\n");
        } else {
            RtbConsole.AppendText("Proxy Test: Failed\n");
        }

        //Close the browser
        driver.Quit();

【问题讨论】:

  • 如果有人对这个问题的答案感兴趣,它真的不可能像我试图那样做我最终在单独的线程中运行驱动程序部分,然后使用委托函数来应用控制台更新。

标签: c# .net selenium


【解决方案1】:

我是这个网站的新手,如果这没有帮助,我深表歉意。但是,当我在 C# 中编写 selenium(webdriver) 测试时,我通常不使用 append 命令。尝试以不同的方式接近控制台,例如

Console.WriteLine("Text you wish to be outputted to the Console"); 
//OR MAYBE 
Console.Write("Text you wish to be outputted to the Console"); 

此外,我不确定同时执行两个命令实际上是否可能,但是,您可以使输出取决于其他选择的代码执行、使用 if 语句或尝试 catch 等。

希望这会有所帮助!干杯!

【讨论】:

  • 我等待了一段时间的答案,我会试一试。谢谢
  • 不,它并没有真正起作用我想我需要找到一种方法在单独的线程或其他东西中运行它并监视线程。
猜你喜欢
  • 2017-01-24
  • 2015-05-18
  • 2023-03-23
  • 1970-01-01
  • 2015-05-21
  • 1970-01-01
  • 2014-09-03
  • 1970-01-01
  • 2021-01-04
相关资源
最近更新 更多