使用java查找selenium对象标签 [英] Finding selenium object tag using java
问题描述
以前我的代码工作没有问题,并且能够使用硒在没有问题的情况下在网页中查找对象标记。我使用chrome驱动程序来访问页面,因为我注意到当我使用IE时DOM没有显示任何内容,我需要访问对象标签的内容。也就是说,我使用的代码如下所示:
browser.manage()。timeouts()。implicitlyWait(5,TimeUnit .SECONDS);
WebElement object = browser.findElement(By.tagName(object));
browser.switchTo().frame(object);
目前,我遇到了一个问题,虽然我在第二行发现错误,阅读:
导致:java.lang.ClassCastException:com.google.common.collect.Maps $ TransformedEntriesMap无法转换为org.openqa.selenium.WebElement
我在看的对象标签(大部分是由于删除与业务相关的部分)如下:
< object type =image / svg + xmldata =classifiedwidth =1600pxheight =900px> ...< / object>
有什么想法可能是错误的,或者是否有更好的方法在java中执行此操作?
在Chromium项目中报告了一些问题: 我们在内部自动化项目中遇到了这样的问题,但我们也可以选择查询
div
而不是 object
(我们如何修复它)。
我将测试改回查询 object
元素,并且我得到了相同的异常:
在端口18276上启动ChromeDriver 2.18.343837(52eb4041461e46a6b73308ebb19e85787ced4281)
只允许本地连接。
线程main中的异常org.openqa.selenium.WebDriverException:返回的值无法转换为WebElement:{}
Build info:version:'2.47.1',revision:'unknown',time :'2015-07-30 11:02:44'
系统信息:主机:'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.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)
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)
导致:java.lang.ClassCastException:com.google.common.collect.Maps $ TransformedEntriesMap无法转换为org.openqa .selenium.WebElement
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:353)
... 9 more
浏览器: Google Chrome版本47.0.2526.106(64位)
(今天的最新稳定版本[OS X平台])
I previously had my code working no problems and was able to find an object tagin a web page using selenium with no problem. I'm using a chrome driver to access the page as I noticed that the DOM showed nothing inside it when I used IE and I need to reach the contents of the object tag. That said, the code I used was as follows:
browser.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
WebElement object = browser.findElement(By.tagName("object"));
browser.switchTo().frame(object);
At the moment, I'm having a problem though where I get an error from the second line that reads:
Caused by: java.lang.ClassCastException: com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to org.openqa.selenium.WebElement
The object tag I'm looking at is (mostly, due to removing business related sections) as follows:
<object type="image/svg+xml" data="classified" width="1600px" height="900px">...</object>
Any idea of what might be wrong or if there's a better way to do this in java?
There were the issues reported at Chromium project:
- https://code.google.com/p/chromium/issues/detail?id=543932
- https://code.google.com/p/chromium/issues/detail?id=554001
We had such issue in the internal automation project but we also had an option to query div
instead of object
(the way how we fixed it).
I changed the tests back to querying object
element and I got the same exception:
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
Browser: Google Chrome Version 47.0.2526.106 (64-bit)
(latest stable version for today [OS X platform])
这篇关于使用java查找selenium对象标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!