标签: screenshotexception

如何使用java实现与Selenium WebDriver的PhantomJS

我真的很生气.我有这个代码:

public class Creazione extends TestCase {
    private PhantomJSDriver driver;
    private String baseUrl;
    private boolean acceptNextAlert = true;
    private StringBuffer verificationErrors = new StringBuffer();

    @Before
    public void setUp() throws Exception {
        File file = new File("C:/Program Files/phantomjs-1.9.7-windows/phantomjs.exe");
        System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
        driver = new PhantomJSDriver();
        baseUrl = "http://www.gts.fiorentina.test/";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get(baseUrl + "/Account/Login.aspx?ReturnUrl=%2f");
        findDynamicElement(By.id("tbUserName_I"), 2000);
        driver.findElement(By.id("tbUserName_I")).clear();
        driver.findElement(By.id("tbUserName_I")).sendKeys("rogai");
        driver.findElement(By.id("tbPassword_I")).clear();
        driver.findElement(By.id("tbPassword_I")).sendKeys("Fiorentina2014!");
        driver.findElement(By.id("btnLogin_CD")).click();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void testCreazione() throws Exception {
        driver.get(baseUrl + "/SegreteriaSportiva/Calciatori.aspx");
        findDynamicElement(By.cssSelector("#ASPxButton1_CD > span"), 2000);
        driver.findElement(By.cssSelector("#ASPxButton1_CD > span")).click();
        findDynamicElement(By.id("FrmEdit_TS_TipoPersonaId_FK_B-1"), 2000); …
Run Code Online (Sandbox Code Playgroud)

java selenium phantomjs selenium-webdriver screenshotexception

8
推荐指数
2
解决办法
6万
查看次数

屏幕截图异常:已截屏

这是PhantomJS Session的Stack Trace.它随机地做到这一点.我看到它说:Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken.该代码与Firefox浏览器完美配合,但无头无效.

我在这个问题上一直在做的谷歌搜索很少,但关于PhantomJS的网页没有截屏,我所做的只是试图点击一个元素.或者我误解了,实际发生的是PhantomJS正在拍摄失败的点击尝试的截图?

[ERROR - 2015-06-08T16:02:30.402Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1433779350383:262 in error
Exception in thread "main" org.openqa.selenium.NoSuchElementException: {"errorMessage":"Unable to find element with xpath'//*[@id=\"linput_806867695_10_9022592247_0\"]'","request":{"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"78","Content-Type":"application/json; charset=utf-8","Host":"localhost:31177","User-Agent":"Apache-HttpClient/4.3.6 (java 1.5)"},"httpVersion":"1.1","method":"POST","post":"{\"using\":\"xpath\",\"value\":\"//*[@id\\u003d\\\"linput_806867695_10_9022592247_0\\\"]\"}","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/828cd8e0-0df7-11e5-835a-03db015d40d4/element"}}
Command duration or timeout: 5.60 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'debserver', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'i386', os.version: '3.16.0-4-686-pae', …
Run Code Online (Sandbox Code Playgroud)

java selenium phantomjs screenshotexception

5
推荐指数
0
解决办法
4001
查看次数

通过Selenium PhantomJS在Exception中截取的屏幕截图

有一段时间我在Selenium PhantomJS测试中得到一个例外,其中包括下面的文本

Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
Run Code Online (Sandbox Code Playgroud)

那么截图真的像消息一样被拍了吗?这个屏幕截图会保存在哪里?我检查了程序目录,没有保存图像.

selenium screenshot phantomjs screenshotexception

5
推荐指数
1
解决办法
2747
查看次数