With Scala 2.8.1, SBT 0.7.4, WebDriver HTMLUnit 2.6. In the SBT console REPL ...
scala> e.findElement[tab]
findElement findElementById findElementByLinkText findElementByPartialLinkText
findElementByTagName findElementByXPath findElements findElementsById
findElementsByLinkText findElementsByPartialLinkText findElementsByTagName findElementsByXPath
scala> e.findElementByXPath[tab]
def findElementByXPath(String): org.openqa.selenium.WebElement
scala> e.findElementByXPath("/td[0]")
<console>:12: error: value findElementByXPath is not a member of org.openqa.selenium.WebElement
e.findElementByXPath("/td[0]")
^
( [tab]
s are added by me for the purpose of illustrating tab completion)
So, the REPL tells me that findElementByXPath(String):WebElement
exists on e
, but when I invoke it, it's not found. What gives?
Note that org.openqa.selenium.WebElement
doesn't have these methods, but classes implementing it like org.openqa.selenium.htmlunit.HtmlUnitWebElement
do.
My best guess is that tab-completion shows all public (or protected; see Daniel's answer) methods of e
's class , but the type of the variable is org.openqa.selenium.WebElement
, so these methods can't actually be called.
See here:
scala> class X {
| def m1 = 1
| protected def m2 = 2
| private def m3 = 3
| }
defined class X
scala> class Y extends X {
| def m4 = 4
| }
defined class Y
scala> val x: X = new Y
x: X = Y@12524b0
scala> x.
asInstanceOf equals getClass hashCode isInstanceOf m1 m2 m4
notify notifyAll toString wait
So, m2
shows up even though you can't use it because it is protected, and m4
shows up even though you can't use it (without casting or matching) because x
's type is X
, and m4
is of class Y
(the actual class
, not type
, of x
).
Next question: is this intentional? Well, not really, but there are things of higher priority to fix. Patches are welcome, of course. :-)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.