- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在使用 Java 中的 phantomjs 运行 selenium 测试时遇到问题。我知道 phantomjs 不支持 flash。我正在使用 chromedriver 运行双重测试,没有启用闪存和幻像。在 chromedriver 显示未启用 Flash 插件的页面上,它只是加载页面的其余部分并正确读取它。幻影测试在这里抛出超时异常:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(),'"+s +"')]")));
有什么想法吗?
完整的堆栈跟踪:
org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for visibility of element located by By.xpath: //span[contains(text(),'Swiss Super League')]
Build info: version: '2.41.0', revision: '3192d8a6c4449dc285928ba024779344f5423c58', time: '2014-03-27 11:29:39'
System info: host: 'countZero', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-40-generic', java.version: '1.8.0_25'
Driver info: org.openqa.selenium.phantomjs.PhantomJSDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, handlesAlerts=false, databaseEnabled=false, version=1.9.0, platform=LINUX, browserConnectionEnabled=false, proxy={proxyType=direct}, nativeEvents=true, acceptSslCerts=false, driverVersion=1.0.3, locationContextEnabled=false, webStorageEnabled=false, browserName=phantomjs, takesScreenshot=true, driverName=ghostdriver, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 9422d0d0-7731-11e4-9730-f784ef9dac1a
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:79)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:228)
at com.hawaii.gatherer.parsers.betfred.parse(betfred.java:88)
at com.hawaii.gatherer.parsers.Parser.call(Parser.java:93)
at com.hawaii.gatherer.parsers.Parser.call(Parser.java:27)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.openqa.selenium.NoSuchElementException: Error Message => 'Unable to find element with xpath '//span[contains(text(),'Swiss Super League')]''
caused by Request => {"headers":{"Accept":"application/json, image/png","Connection":"Keep-Alive","Content-Length":"73","Content-Type":"application/json; charset=utf-8","Host":"localhost:18409"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"xpath\",\"value\":\"//span[contains(text(),'Swiss Super League')]\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/9422d0d0-7731-11e4-9730-f784ef9dac1a/element"}
Command duration or timeout: 795 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.41.0', revision: '3192d8a6c4449dc285928ba024779344f5423c58', time: '2014-03-27 11:29:39'
System info: host: 'countZero', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-40-generic', java.version: '1.8.0_25'
Driver info: org.openqa.selenium.phantomjs.PhantomJSDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, handlesAlerts=false, databaseEnabled=false, version=1.9.0, platform=LINUX, browserConnectionEnabled=false, proxy={proxyType=direct}, nativeEvents=true, acceptSslCerts=false, driverVersion=1.0.3, locationContextEnabled=false, webStorageEnabled=false, browserName=phantomjs, takesScreenshot=true, driverName=ghostdriver, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 9422d0d0-7731-11e4-9730-f784ef9dac1a
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:445)
at org.openqa.selenium.By$ByXPath.findElement(By.java:357)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:340)
at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:730)
at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:39)
at org.openqa.selenium.support.ui.ExpectedConditions$4.apply(ExpectedConditions.java:130)
at org.openqa.selenium.support.ui.ExpectedConditions$4.apply(ExpectedConditions.java:126)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
... 7 more
Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
Build info: version: '2.41.0', revision: '3192d8a6c4449dc285928ba024779344f5423c58', time: '2014-03-27 11:29:39'
System info: host: 'countZero', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-40-generic', java.version: '1.8.0_25'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:125)
... 17 more
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Error Message => 'Unable to find element with xpath '//span[contains(text(),'Swiss Super League')]''
caused by Request => {"headers":{"Accept":"application/json, image/png","Connection":"Keep-Alive","Content-Length":"73","Content-Type":"application/json; charset=utf-8","Host":"localhost:18409"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"xpath\",\"value\":\"//span[contains(text(),'Swiss Super League')]\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/9422d0d0-7731-11e4-9730-f784ef9dac1a/element"}
Build info: version: '2.41.0', revision: '3192d8a6c4449dc285928ba024779344f5423c58', time: '2014-03-27 11:29:39'
System info: host: 'countZero', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-40-generic', java.version: '1.8.0_25'
Driver info: driver.version: unknown
重现问题的代码:
public void test() throws InterruptedException {
//System.setProperty("webdriver.chrome.driver", Application.chromeDriverPath);
//WebDriver driver= new ChromeDriver();
WebDriver driver=new PhantomJSDriver();
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
driver.manage().window().setSize(new Dimension(1280, 800));
driver.get("http://www.betfred.com/sport");
WebElement footballLink=driver.findElement(By.linkText("Football"));
footballLink.click();
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement europeanLink= wait.until(ExpectedConditions.visibilityOfElementLocated(By.partialLinkText("European Leagues")));
europeanLink.click();
wait = new WebDriverWait(driver, 10);
WebElement leagueLink= wait.until(ExpectedConditions.visibilityOfElementLocated(By.partialLinkText("Italian Serie A")));
leagueLink.click();
wait = new WebDriverWait(driver, 10);
WebElement finalLeagueLink=wait.until(ExpectedConditions.elementToBeClickable((By.xpath("//a[contains(text(),'Italian Serie A') and contains(@class,'action')]"))));
Thread.sleep(1000);
finalLeagueLink.click();
driver.switchTo().frame("sportframe");
wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(),'Italian Serie A')]")));
}
请注意,如果将其更改为 chromedriver,则不会引发错误,并且您可以看到页面已加载。对于幻像,页面未加载,因此出现错误。也许我应该将其作为错误报告提交到 github 中?
编辑
我在这里提交了一个新问题 https://github.com/ariya/phantomjs/issues/12784
最佳答案
PhantomJS 的默认视口(viewport)大小为 400x300。对于大多数使用固定宽度的网站来说,这太小了,这就是为什么会出现滚动条,这就是为什么在使用 Selenium Webdrivers 元素时无法与之交互,因为它们隐藏在 View 之外。对于其他网站,将显示移动网站(可能基于媒体查询),并且使用的元素可能与桌面网站不同(并且具有不同的选择器)。
要解决此问题,您应该在打开页面之前将视口(viewport)设置为类似于桌面的内容(如图 here ):
driver.manage().window().setSize(new Dimension(1280, 800));
这很可能与页面上存在 Flash 对象而 PhantomJS 无法加载它们这一事实无关。如果它确实与此有关,那么脚本/PhantomJS 就会更快崩溃。
<小时/>将用户代理字符串设置为代表 PhantomJS 功能的内容也可能会很好。一些网站(例如谷歌)将使用网络协议(protocol)或提供在 PhantomJS 1.x 中无法运行的 JavaScript。所以对于 PhantomJS 1.x 来说,这将是
String userAgent = "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1";
System.setProperty("phantomjs.page.settings.userAgent", userAgent);
关于java - 如果有 flash 插件,phantomjs 无法加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27177461/
我正在尝试开始使用 Mermaid CLI,但是当我尝试针对我的源文件运行它时,它说找不到 phantomjs。 (我运行的是 Win 7 64。) C:\Users\Chris\Documents>
我正在使用PhantomJS来调用网页,如下所示: page.open('http://example.com', function (s) { console.log(page.content)
如果有这样的功能,我需要更改Phantomjs自动清除缓存的默认时间。有什么想法吗? 最佳答案 应该是您正在寻找的功能: https://github.com/ariya/phantomjs/issu
我想从我的程序运行 PhantomJs 脚本,但由于脚本可能不是我写的,我需要确保 PhantomJs 在执行完成或因任何原因(例如无效语法、超时、 ETC)。到目前为止,我读到的所有内容都说你必须始
在 Package JSON 中,我尝试了许多不同版本的 karma-phantomjs-launcher、phantomjs,包括 phantomjs-prebuilt。 当前包 JSON “开发依
我的脚本有一些语法错误,但 PhantomJS 没有显示任何错误,而是没有显示任何内容。如果脚本有错误,为什么 Phantom JS 不显示解析错误? 在以下 PhantomJS 脚本(通过 Wind
我有一些需要填写的动态输入表单。问题是要填写表格,我需要访问另一个页面以获取取决于上一页输入的数据。因此,在我获得数据然后返回表单后,表单已经更改,因此我需要在获取数据时保持该表单打开。那么问题是如何
PhantomJS 在为我捕获网页到图像文件方面做得很好。我正在使用基于 rasterize.js 的脚本。 但是,对于某些固定大小的 Web 元素,我需要生成的图像与 Web 元素的大小相匹配。 例
我正在将 PhantomJS headless 浏览器集成到我的一个项目中(目前使用 1.6 版)。在大多数情况下,它在完成我需要完成的工作方面做得很好。但是,WebPage.open() 调用工作方
是否可以在page.evaluate中传递变量? function myFunction(webpage, arg1, arg2){ var page = require('webpage').cre
有没有办法始终如一地检测 PhantomJS/CasperJS?我一直在处理用它构建的一系列恶意垃圾邮件机器人,并且能够根据某些行为基本上阻止它们,但是我很好奇是否有一种坚如磐石的方法来了解 Casp
有没有办法拦截资源请求并直接从处理程序给出响应?像这样的事情: page.onRequest(function(request){ request.reply({data: 123}); });
phantomjs 有配置 loadImage, 但我想要更多, 如何控制phantomjs跳过下载某种资源, 比如css等... ===== 好消息:已添加此功能。 https://code.goo
我正在尝试在 PhantomJS (2.1.1) 的 page.evaulate() 调用中使用 WebSocket。当尝试连接到 WebSocket 服务器时,出现以下错误: 安全错误:DOM 异常
我正在使用 PhantomJS 1.8,但遇到了一个限制——您无法指定它用于磁盘缓存的目录。我将其添加到他们的问题跟踪系统中,但由于以前没有它,所以我不希望它很快添加。 因此,我正在寻找解决此限制的方
我想渲染一个仅在用户滚动页面时加载图像的页面。仅设置 page.scrollPosition 没有任何效果。我需要一些可以随时间改变滚动位置的东西。 最佳答案 不确定这是否是最好的方法,但它确实有效。
我正在尝试使用 PhantomJS 设置远程调试,但运气不佳。我按照 https://github.com/ariya/phantomjs/wiki/Troubleshooting 上的说明进行操作。
在 PhantomJS 中,webpage.open 会使用状态参数设置为“成功”或“失败”的回调。根据文档,如果没有发生网络错误,则“成功”,否则“失败”。有没有办法查看导致失败的底层网络错误? 当
有什么方法可以使用 phantomjs 请求资源并能够到达响应的主体吗? 最佳答案 更新:关于“获取并使用所有其他资源(如图像、CSS、字体等)做某事”的其他可能含义,我最近在博客上写了 how to
在运行 PhantomJS 提供的 rasterize.js 示例时,我发现我必须等待 20 秒或更长时间才能生成网页图像。 有没有可能在不消耗大量资源的情况下加快速度的方法?我基本上希望快速生成从加
我是一名优秀的程序员,十分优秀!