要在Selenium 2中制作屏幕截图,您需要执行以下 *** 作
driver = new FireFoxDriver(); // Should work in other Browser Driversdriver.Navigate().GoToUrl("http://www.theautomatedtester.co.uk");Screenshot ss = ((ITakesScreenshot) driver).GetScreenshot();//Use it as you want nowstring screenshot = ss.Asbase64EnpredString;byte[] screenshotAsByteArray = ss.AsByteArray;ss.SaveAsFile("filename", ImageFormat.Png); //use any of the built in image formatingss.ToString();//same as string screenshot = ss.Asbase64EnpredString;
我很快在IronPython Repl中对其进行了测试,因此该代码应该可以正常工作。请参阅下面的IronPython代码
import clrclr.AddReference("WebDriver.Common.dll")clr.AddReference("WebDriver.Firefox.dll")from OpenQA.Selenium import *from OpenQA.Selenium.Firefox import *driver = FirefoxDriver()driver.Navigate().GoToUrl("http://www.theautomatedtester.co.uk")s = driver.GetScreenshot()s.AsbaseEnpredString# HUGE string appears in the REPL
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)