phantomjsdriver java_java-PhantomJSDriver找到了元素,但仍未定义

我在PhantomJSDriver和Java上遇到了一个奇怪的问题,

我试图单击这样的链接:

WebElement loginButton = wait.until(

ExpectedConditions.elementToBeClickable(By.xpath("//a[@ui-sref='login']"))

);

LOG.debug("Login Button Found : ["+loginButton.getAttribute("href")+"]" );

loginButton.click();

使用Crome Driver,我没有任何问题,但是使用phantomsJS(2.0.0(或1.9.7 / 1.9.8)和GhostDriver 1.2.0,我有这种错误:

[DEBUG - 2015-05-04T09:46:03.610Z] WebElementLocator - _handleLocateCommand - Element(s) Search Start Time: 1430732763610

[DEBUG - 2015-05-04T09:46:03.612Z] WebElementLocator - _find.locator - {"using":"xpath","value":"//a[@ui-sref='login']"}

[DEBUG - 2015-05-04T09:46:03.624Z] WebElementLocator - _locateElement.locator - {"using":"xpath","value":"//a[@ui-sref='login']"}

[DEBUG - 2015-05-04T09:46:03.624Z] WebElementLocator - _locateElement.findElementResult - {"status":0,"value":{"ELEMENT":":wdc:1430732763623"}}

[DEBUG - 2015-05-04T09:46:03.624Z] WebElementLocator - _handleLocateCommand.elements - {"status":0,"value":{"ELEMENT":":wdc:1430732763623"}}

[DEBUG - 2015-05-04T09:46:03.624Z] WebElementLocator - _handleLocateCommand.rootElement - BODY

[DEBUG - 2015-05-04T09:46:03.625Z] WebElementLocator - _handleLocateCommand - Element(s) Found. Search Stop Time: 1430732768610

和错误消息:

org.openqa.selenium.WebDriverException: {"errorMessage":"undefined is not an object (evaluating '(y(a)?y(a).parentWindow||y(a).defaultView:window).getComputedStyle(a,null).MozTransform.match')","request":{"headers":{"Accept":"application/json, image/png","Cache-Control":"no-cache","Connection":"Keep-Alive","Host":"localhost:7356"},"httpVersion":"1.1","method":"GET","url":"/displayed","urlParsed":{"anchor":"","query":"","file":"displayed","directory":"/","path":"/displayed","relative":"/displayed","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/displayed","queryKey":{},"chunks":["displayed"]},"urlOriginal":"/session/5f287dd0-f242-11e4-9753-1726c362b9fc/element/%3Awdc%3A1430732763623/displayed"}}

Command duration or timeout: 229 milliseconds

我添加了显式的等之前的等待,但是它什么也没做…

如果那是怪异的部分,如果我改为尝试以下代码:

d.findElement(By.xpath("//a[@ui-sref='login']"));

LOG.debug("Login Button Found : ["+loginButton.getAttribute("href")+"]" );

loginButton.click();

我可以访问href属性!

但是click()方法失败

[编辑]

第一个PhanstomJS配置看起来像这样:

// Change "User-Agent" via page-object capabilities

sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "userAgent", "My User Agent - Chrome");

// Disable "web-security", enable all possible "ssl-protocols" and "ignore-ssl-errors" for PhantomJSDriver

sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {

"--web-security=false",

"--ssl-protocol=any",

"--ignore-ssl-errors=true",

"--webdriver-loglevel=DEBUG"

});

// Fetch configuration parameters

// "phantomjs_exec_path"

if (sConfig.getProperty("phantomjs_exec_path") != null) {

sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, sConfig.getProperty("phantomjs_exec_path"));

} else {

throw new IOException(String.format("Property '%s' not set!", PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY));

}

}

谢谢您的帮助 !

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值