1

嗨,我第一次使用 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();
4

1 回答 1

0

我是这个网站的新手,所以如果这没有帮助,我深表歉意。但是,当我在 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 等。

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

于 2012-09-06T00:12:21.257 回答