Selenium Webdriver,打开驱动程序后,C#输出到控制台 [英] Selenium Webdriver, C# output to console after opening driver
问题描述
您好,我是第一次使用Selenium,并且正在执行以下代码.它运行良好,但是在打开firefox之后,它不会输出到控制台,因为代码表明在代码中的所有步骤完成后应该执行所有操作.
Hi I am using Selenium for the first time and I was doing the following code. It runs fine but after opening firefox it wont output to console as the code says it should it will do all of it after all the steps in the code are complete.
所以我的问题是,如何在实际运行该步骤的同时将文本输出到控制台?
So my question is how do I make that text output to console while its actually running the step?
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命令.尝试以其他方式使用控制台,例如
I'm new to this site, so i apologize if this is not helpful. However, when i am writing selenium(webdriver) tests in C#, i generally do not use the append command. Try approaching the console differently, such as
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等.
In addition, i am not sure that simultaneously executing two commands is actually possible, however, you can make the output contingent upon other chosen code executing, using if statements, or maybe try catch etc.
希望这会有所帮助!干杯!
Hope that this helps! Cheers!
这篇关于Selenium Webdriver,打开驱动程序后,C#输出到控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!