繁体   English   中英

Selenium Webdriver,打开驱动程序后,C#输出到控制台

[英]Selenium Webdriver, C# output to console after opening driver

嗨,我是第一次使用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#编写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等。

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM