Kami
Kami

Reputation: 49

Finding selenium object tag using java

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?

Upvotes: 4

Views: 2406

Answers (2)

drets
drets

Reputation: 2805

There were the issues reported at Chromium project:

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])

Upvotes: 2

N..
N..

Reputation: 956

I think it is synchronous problem.

I will suggest you to use WebDriver Wait

Here is code that you can try:

WebDriver driver = new FirefoxDriver();
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(By.tag("object")));

Upvotes: 1

Related Questions