Right now I am trying to click() on an element, if I get an
ElementNotVisibleException I understand it is not usable.
Are there any other alternatives?
Thank you for your answers.
There are several methods you can call to query the state of your
element[1]:
element.getSize() - // Returns the size of the element (condition 1)
element.isDisplayed(); // Returns whether the element is displayed on
the page (condition 2)
-- Jason
[1] You can find the full javadoc for WebDriver here:
http://selenium.googlecode.com/svn/webdriver/javadoc/index.html
> Is there such a functionality like WebElement.isElementUsable() yet?
I don't think it's currently exposed by the API, which language are
you using?
--
Miki
> > Thank you for your answers.- Alıntıyı gizle -
>
> - Alıntıyı göster -
First, create a function that allows you to figure out if the element
is visible yet (I'm writing this into my email client, so it may not
compile: you get the idea)
public ExpectedCondition<WebElement>
visibilityOfElementLocated(final By by) {
return new ExpectedCondition<WebElement>() {
public WebElement apply(WebDriver driver) {
WebElement element = driver.findElement(by);
if (!(element instanceof RenderedWebElement))
return element;
return ((RenderedWebElement) element).isDisplayed() ?
element : null;
}
};
};
Note that the function returns a WebElement. This is because the
"until" method of "Wait" returns whatever the function does. This
means that we can avoid an extra element lookup, and our tests become
a little bit more readable. We can then use it, like so:
Wait<WebDriver> wait = new WebDriverWait(driver);
WebElement element = wait.
until(visibilityOfElementLocated(By.id("foo:"));
It should also be possible to use the PageFactory and a (unwritten)
ElementLocatorFactory that waits until an element is visible before
calling (certain?) methods on an element.
Which is a really long way of saying that I have no plans to add an
"isUsable" method to an element because there are already ways of
handling what you want. I hope that the reasoning makes sense and that
this helps you figure out a nice way of doing what you need.
Regards,
Simon
2009/12/19 bitkidoku <b.e...@gmail.com>:
> --
>
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
>
>
>
I see a cast to RenderedWebElement in apply(), this means this Wait
function will only be available for drivers other than HtmlUnit. What
I am looking for is a way to achieve the same thing regardless of the
driver.
As I explained before, the best way I found so far is to click() on an
element, so I know if it is usable or not (if click throws
ElementNotVisible I know that it is not usable), and this approach
works with all drivers. But this solution looks dirty, and does not
feel right; that is why I asked for a better way.
Frankly, if all drivers can throw ElementNotVisibleException, an
element should tell if element itself is visible (or usable)
regardless of driver.
I am sorry for my English, since it is not my native language, I may
not have made myself clear.
> 2009/12/19 bitkidoku <b.ev...@gmail.com>:
>
>
>
> > afaik, isDisplayed() is a method of RenderedWebElement not WebElement,
> > but it is possible to get ElementNotVisible exception even in
> > HtmlUnitDriver. I am looking for a generic solution.
>
> > On 18 Aralýk, 19:46, Jason <jmle...@gmail.com> wrote:
> >> WebDriver does not let you click on an element if the user would not
> >> be able to click on it. This means two conditions must hold: 1) the
> >> element has width and height, and 2) the element is not hidden by CSS
>
> >> There are several methods you can call to query the state of your
> >> element[1]:
>
> >> element.getSize() - // Returns the size of the element (condition 1)
> >> element.isDisplayed(); // Returns whether the element is displayed on
> >> the page (condition 2)
>
> >> -- Jason
>
> >> [1] You can find the full javadoc for WebDriver here:http://selenium.googlecode.com/svn/webdriver/javadoc/index.html
>
> >> On Dec 18, 4:21 am, bitkidoku <b.ev...@gmail.com> wrote:
>
> >> > Is there such a functionality like WebElement.isElementUsable() yet?
>
> >> > Right now I am trying to click() on an element, if I get an
> >> > ElementNotVisibleException I understand it is not usable.
>
> >> > Are there any other alternatives?
>
> >> > Thank you for your answers.- Alýntýyý gizle -
>
> >> - Alýntýyý göster -
Regards,
Simon