Tag: phantomjs

PHantom JS 50%的时间都失败了

我搜索一个文本框,然后尝试用字符串填充它。 这是代码: var fname = _driver.FindElement(By.Name(“iFirstName”), 50); if(fname!=null) { do { System.Threading.Thread.Sleep(500); } while (!fname.Displayed); fname.SendKeys(myName); } FindElement函数是这样的: public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds) { if (timeoutInSeconds > 0) { var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds)); return wait.Until(drv => drv.FindElement(by)); } return driver.FindElement(by); } 有些时候文本框中填充了字符串,有时我收到此错误: System.InvalidOperationException: {“errorMessage”:”‘undefined’ is not an object […]

无法下载PhantomJS生成的pdf

我在将一个PhantomJS生成的文件下载到我的asp.net应用程序时遇到了一些麻烦。 我正在运行phantomJs作为服务器:文件生成正确并保存到PhantomJS文件夹中的磁盘,但在传输过程中发生了一些事情并包含在我的Http响应流中。 该文件是由浏览器下载的,但是当我尝试打开它时,文件错误,并显示无法打开的消息。 我怀疑它在流传输中被破坏了? 我想避免从文件系统中存储的位置读取pdf,而是从PhantomJS返回的响应中取出它 PhantomJS代码: page.open(url, function (status) { page.render(fullFileName); var fs = require(‘fs’); var pdfContent = fs.read(fullFileName); response.statusCode = 200; response.headers = { ‘Cache’: ‘no-cache’, ‘Content-Type’: ‘application/pdf’, ‘Connection’: ‘Keep-Alive’, ‘Content-Length’: pdfContent.length }; response.setEncoding(“binary”); response.write(pdfContent); }); ASP.NET代码: public ActionResult DownloadPdfFromUrl(ConvertionModel model) { HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(“http://localhost:8080”); ASCIIEncoding encoding = new ASCIIEncoding(); string postData = […]

使用phantomjs进行Windows身份validation

我正在研究phantomjs作为我最新项目中UI自动化的可能解决方案,但我似乎无法让Windows身份validation正常工作。 我已经尝试设置page.settings.userName和page.settings.password ,但下面的代码片段总是获得401 ,底层堆栈不会解决它。 我的搜索失败了,所以我来到社区寻求帮助。 var page = require(‘webpage’).create(); page.onResourceReceived = function(response) { phantom.exit(response.status); }; page.open(‘http://bing.com’);

如何点击点击按钮后新生成的’new ? 在C#selenium

在我点击按钮之前,页面的html代码如下 但点击一个按钮后,代码就像这里的图片一样 我试图找到新按钮,但始终“无法找到元素〜@”] wait.Until(ExpectedConditions.ElementExists(By.XPath(“//*[@id=’layerContainer’]/div/section/div/div[2]/form/article/footer/div/button”))); IWebElement submit2 = this.driver.FindElement(By.XPath(“//*[@id=’layerContainer’]/div/section/div/div[2]/form/article/footer/div/button”)); submit2.Click(); 我的目的是找出新生成的按钮并单击它,但它无法一直找到新按钮,有什么方法可以解决它吗?

如何在PhantomDriver(无头浏览器)中隐藏FirefoxDriver(使用Selenium)而没有findElement函数错误?

我尝试制作隐藏的FirefoxDriver。 根据我的研究,我必须使用PhantomJSDriver但是当我使用PhantomJSDriver时,driver.FindElement语句不再起作用。 var options = new PhantomJSOptions(); options.AddAdditionalCapability(“phantomjs.page.settings.userAgent”, “Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36”); PhantomJSOptions p = new PhantomJSOptions(); var service = PhantomJSDriverService.CreateDefaultService(); service.SslProtocol = “any”; service.ProxyType = “http”; service.WebSecurity = false; service.IgnoreSslErrors = true; var driver = new PhantomJSDriver(service, options); driver.Navigate().GoToUrl(“https://www.google.com.tr/”); Thread.Sleep(5000); driver.FindElement(By.XPath(“//*[@id=’lst-ib’]”)).SendKeys(“edd”); string s = driver.Url; Console.WriteLine(s); 错误信息: WebDriver.dll中发生未处理的“OpenQA.Selenium.NoSuchElementException”类型exception […]

C#使用PhantomJS webdriver ExecutePhantomJS过滤掉图像的示例

我希望能够有选择地打开和关闭某些图像。 我看过以下文章: PhantomJS如何跳过下载资源 我也发现这篇文章使用python非常相似: 由PhantomJS / Python驱动的Selenium 我假设我可以通过webdriver.ExecutePhantomJS(string script, params object[] args)来做到这一点。 我不知道的是,我是否需要首先通过Selenium PageFactory创建一些页面对象,然后调用此函数? 我怎么能再把它关掉 如何做到这一点的一个例子将非常有帮助。

设置PhantomJS C#中的屏幕尺寸由Selenium驱动

如何设置浏览器屏幕大小? 当我在设置PhantomJS之后进行屏幕截图时,它只显示400px宽的图像。 var driverService = PhantomJSDriverService.CreateDefaultService(); driverService.HideCommandPromptWindow = true; driverService.LoadImages = false; driverService.ProxyType = “none”; using (var driver = new PhantomJSDriver(driverService)) { etc…. }

在Selenium PhantomJSDriver中指定PhantomJS命令行选项

PhantomJS驱动程序是否支持命令行参数? 我需要使用PhantomJS驱动程序运行Selenium测试并禁用Web安全性。 我试过了: PhantomJSOptions options = new PhantomJSOptions(); options.AddAdditionalCapability(“web-security”,false); driver = new PhantomJSDriver(Environment.CurrentDirectory + @”\drivers”, options); 但这似乎不起作用。 PhantomJSDriver是否允许传递命令行参数?

在Azure Web App上运行Selenium

我有一个Azure Web应用程序,当我在控制器上调用Action时,我想用它来屏幕抓取网站,就像这样。 var driver = new PhantomJSDriver(); driver.Url = “http://url.com”; driver.Navigate(); var source = driver.PageSource; var pathElement = driver.FindElementByXPath(“//table[@class=’someclassname’]”); string innerHtml = “”; IJavaScriptExecutor js = driver as IJavaScriptExecutor; if (js != null) { innerHtml = (string)js.ExecuteScript(“return arguments[0].innerHTML;”, pathElement); } return innerHtml; 这在本地工作正常,但是当我上传到我的Azure Web App时,我收到此错误 无法在http:// localhost:51169 /上启动驱动程序服务 我认为这与防火墙有关,因为我需要在应用程序第一次运行时在防火墙设置中批准PhantomJS。 我的问题是如何在Azure中部署这个工作? 它是否可能,或者我是否需要将其配置为unit testing并在Visual Studio中运行?

使用C#运行Phantomjs以获取网页快照

我正在尝试使用phantomjs抓取我自己网站的快照 – 基本上,这是创建用户提交内容的“预览图像”。 我在服务器上安装了phantomjs并确认从命令行运行它对适当的页面工作正常。 但是,当我尝试从网站上运行它时,似乎没有做任何事情。 我已经确认正在调用代码,幻像实际上正在运行(我监视过程,并且当我调用它时可以看到它出现在进程列表中) – 但是,没有生成图像。 我不知道我应该在哪里找出为什么它不会创建图像 – 任何建议? 相关代码块如下: string arguments = “/c rasterize.js http://www.mysite.com/viewcontent.aspx?id=123″; string imagefilename = @”C:\inetpub\vhosts\mysite.com\httpdocs\Uploads\img123.png”; Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.CreateNoWindow = false; p.StartInfo.FileName = @”C:\phantomjs.exe”; p.StartInfo.Arguments = arguments + ” ” + imagefilename; p.Start(); string output = p.StandardOutput.ReadToEnd(); p.WaitForExit();