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