使用java查找selenium对象标记

我以前让我的代码没有问题,并且能够使用selenium在网页中找到一个没有问题的对象标记.我正在使用chrome驱动程序访问页面,因为我注意到当我使用IE时,DOM内部没有显示任何内容,我需要访问对象标记的内容.也就是说,我使用的代码如下:

browser.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
WebElement object = browser.findElement(By.tagName("object"));
browser.switchTo().frame(object);

目前,我遇到了问题,但是我从第二行看到的错误是:

Caused by: java.lang.ClassCastException: com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to org.openqa.selenium.WebElement

我正在查看的对象标签(主要是由于删除与业务相关的部分)如下所示:

<object type="image/svg+xml" data="classified" width="1600px" height="900px">...</object>

知道什么可能是错的,或者在java中有更好的方法吗?

解决方法:

Chromium项目报告了一些问题:

> https://code.google.com/p/chromium/issues/detail?id=543932
> https://code.google.com/p/chromium/issues/detail?id=554001

我们在内部自动化项目中遇到了这样的问题,但我们也有一个选项来查询div而不是object(我们修复它的方式).

我将测试更改回查询对象元素,我得到了同样的异常:

Starting ChromeDriver 2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281) on port 18276
Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {}
Build info: version: '2.47.1', revision: 'unknown', time: '2015-07-30 11:02:44'
System info: host: 'xxx-MacBook-Pro-4.local', ip: 'xxx.xxx.x.xx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11', java.version: '1.7.0_71'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByTagName(RemoteWebDriver.java:413)
    at org.openqa.selenium.By$ByTagName.findElement(By.java:331)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:340)
    at Main.main(Main.java:11)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.ClassCastException: com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to org.openqa.selenium.WebElement
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:353)
    ... 9 more

浏览器:谷歌Chrome版本47.0.2526.106(64位)
(今日最新稳定版[OS X平台])

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐