RemoteWebDriver cannot be cast to org.openqa.selenium.TakesScreenshot (Java)

2,463 views
Skip to first unread message

Zvi Fried

unread,
Feb 14, 2017, 2:18:29 AM2/14/17
to Selenium Users
I'm trying to take a screenshot with RemoteWebDriver of Winium.Desktop. As RemoteWebDriver does not implement TakesScreenshot I declared the object as WebDriver.
WebDriver driver = new RemoteWebDriver(new URL(remoteUrl), desiredCapabilities);

WebDriver augmentedDriver = new Augmenter().augment(driver);
File screenshot = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);

When I try to cast it to I get: java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver cannot be cast to org.openqa.selenium.TakesScreenshot

When I print the driver class name I get RemoteWebDriver although it was declared as WebDriver.

What am I missing?

⇜Krishnan Mahadevan⇝

unread,
Feb 14, 2017, 2:59:15 AM2/14/17
to Selenium Users
RemoteWebDriver does implement TakesScreenshot for a long time that I can remember. So can you please try accessing getScreenshotAs() directly via the RemoteWebDriver instance ?



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/4c4764ca-4a3b-46e2-a82e-5f08e8ab0a2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zvi Fried

unread,
Feb 14, 2017, 6:48:07 AM2/14/17
to Selenium Users
When I try to access the method directly through RemoteWebDriver I get the following Exception (although Eclipse does not give any error on missing method):
java.lang.NoSuchMethodError: org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(Lorg/openqa/selenium/OutputType;)Ljava/lang/Object;

בתאריך יום שלישי, 14 בפברואר 2017 בשעה 09:59:15 UTC+2, מאת Krishnan:
RemoteWebDriver does implement TakesScreenshot for a long time that I can remember. So can you please try accessing getScreenshotAs() directly via the RemoteWebDriver instance ?



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Tue, Feb 14, 2017 at 12:46 PM, Zvi Fried <zvik...@gmail.com> wrote:
I'm trying to take a screenshot with RemoteWebDriver of Winium.Desktop. As RemoteWebDriver does not implement TakesScreenshot I declared the object as WebDriver.
WebDriver driver = new RemoteWebDriver(new URL(remoteUrl), desiredCapabilities);

WebDriver augmentedDriver = new Augmenter().augment(driver);
File screenshot = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);

When I try to cast it to I get: java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver cannot be cast to org.openqa.selenium.TakesScreenshot

When I print the driver class name I get RemoteWebDriver although it was declared as WebDriver.

What am I missing?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

Zvi Fried

unread,
Feb 14, 2017, 6:57:20 AM2/14/17
to Selenium Users
When I try to access the method directly through RemoteWebDriver I get the following Exception (although Eclipse does not give any error on missing method):
java.lang.NoSuchMethodError: org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(Lorg/openqa/selenium/OutputType;)Ljava/lang/Object;

בתאריך יום שלישי, 14 בפברואר 2017 בשעה 09:59:15 UTC+2, מאת Krishnan:
RemoteWebDriver does implement TakesScreenshot for a long time that I can remember. So can you please try accessing getScreenshotAs() directly via the RemoteWebDriver instance ?



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Tue, Feb 14, 2017 at 12:46 PM, Zvi Fried <zvik...@gmail.com> wrote:
I'm trying to take a screenshot with RemoteWebDriver of Winium.Desktop. As RemoteWebDriver does not implement TakesScreenshot I declared the object as WebDriver.
WebDriver driver = new RemoteWebDriver(new URL(remoteUrl), desiredCapabilities);

WebDriver augmentedDriver = new Augmenter().augment(driver);
File screenshot = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);

When I try to cast it to I get: java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver cannot be cast to org.openqa.selenium.TakesScreenshot

When I print the driver class name I get RemoteWebDriver although it was declared as WebDriver.

What am I missing?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

⇜Krishnan Mahadevan⇝

unread,
Feb 14, 2017, 8:17:15 AM2/14/17
to Selenium Users
Can you please share your dependencies ? That looks like a case of mismatch in jars (especially with the selenium-api jar wherein TakesScreenshot interface resides whereas RemoteWebDriver resides in selenium-remote-driver jar)

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/c8ecc109-275c-45a3-932b-364cd2d3d694%40googlegroups.com.

kendall...@bazaarvoice.com

unread,
Feb 15, 2017, 10:48:28 PM2/15/17
to Selenium Users
You should only need to call:
File screenShot = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE)
No need to call Augmenter() unless webDriver is instanceof HtmlUnitDriver
Reply all
Reply to author
Forward
0 new messages