Discussion:
[selenium-users] Confusion over the WebElement interface and it's methods
farooq basha
2017-01-21 16:44:52 UTC
Permalink
Hi All,

First of all I am quite new to selenium,I have a question which I think
would be answered by the experts over here.

WebDriver obj = new ChromeDriver();

perfectly fine as WebDriver is the interface and it is implemented by many
classes and ChromeDriver is one among them,so it's perfeclty valid to
assign the reference variable to the implementing class and we can access
the methods which are define in the interface.

but

WebElement var= driver.findElement(By.id("value"));

var.method();

So I am confused with the above statement as "WebElement is the interface"
and it's reference variable is not assigned to any of it's implementing
class.

We are just assigning it to the other interface and we are able to access
the methods of WebElement.

Can someone help me out with this.


Thanks in advance
--
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+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/e2a5299b-580f-4695-ad1a-fe5c26321ae2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Simon Stewart
2017-01-23 15:06:38 UTC
Permalink
This stuff is covered in many tutorials introducing programming languages.
It might be useful to do some reading up on Java, and specifically its
"type system". Java is a strongly, statically typed language.

You'll find that the ChromeDriver returns a "RemoteWebElement", which
implements the "WebElement" interface. As a rule of thumb, it's best to
refer to the least specific type that conveys meaning in your code (that
is, always prefer to have variables have the type "WebElement" rather than
"RemoteWebElement" in your code)

Simon
Post by farooq basha
Hi All,
First of all I am quite new to selenium,I have a question which I think
would be answered by the experts over here.
WebDriver obj = new ChromeDriver();
perfectly fine as WebDriver is the interface and it is implemented by many
classes and ChromeDriver is one among them,so it's perfeclty valid to
assign the reference variable to the implementing class and we can access
the methods which are define in the interface.
but
WebElement var= driver.findElement(By.id("value"));
var.method();
So I am confused with the above statement as "WebElement is the interface"
and it's reference variable is not assigned to any of it's implementing
class.
We are just assigning it to the other interface and we are able to access
the methods of WebElement.
Can someone help me out with this.
Thanks in advance
--
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
To view this discussion on the web visit https://groups.google.com/d/
msgid/selenium-users/e2a5299b-580f-4695-ad1a-fe5c26321ae2%
40googlegroups.com
<https://groups.google.com/d/msgid/selenium-users/e2a5299b-580f-4695-ad1a-fe5c26321ae2%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAOrAhYHzwpmF_xvjUzxRmPLC5Jk5Ju%2B9%3DDSnMOw_JGJgXhxrbQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Gopi
2017-01-23 05:59:43 UTC
Permalink
A aa = new AImpl();
aa.a();

*Here your reference variable is interface A type But
actual Object is AImpl*.

When you define a new interface, you are defining a new reference data
type. You can use interface names anywhere you can use any other data type
name. If you define a reference variable whose type is an interface, any
object you assign to it must be an instance of a class that implements the
interface.

If your audience is also interested in Selenium Automation Testing, they
can take a look here: Selenium Training
<http://www.credosystemz.com/training-in-chennai/best-selenium-training-in-chennai/>
Post by farooq basha
Hi All,
First of all I am quite new to selenium,I have a question which I think
would be answered by the experts over here.
WebDriver obj = new ChromeDriver();
perfectly fine as WebDriver is the interface and it is implemented by many
classes and ChromeDriver is one among them,so it's perfeclty valid to
assign the reference variable to the implementing class and we can access
the methods which are define in the interface.
but
WebElement var= driver.findElement(By.id("value"));
var.method();
So I am confused with the above statement as "WebElement is the interface"
and it's reference variable is not assigned to any of it's implementing
class.
We are just assigning it to the other interface and we are able to access
the methods of WebElement.
Can someone help me out with this.
Thanks in advance
--
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+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/b430cbb6-40a4-41b8-af2b-f2a627b0fbfd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...