Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the alternative of selenium.isElementPresent in Webdriver

Hi I need to check a drop down field is having given values but those values are not selected so its not getting displayed in the dropdown box. I have following Xpath for the element

//table[contains(@id,'Field')]//tr[td//span[text()='Code']]/preceding-sibling::*[1]/td//select[contains(@id,'GSRCH_FLT')]/option[text()='not=']

which is identifying the element properly in the browser. But when I am using the following webdriver method to verify it

driver.findElement(By.xpath("//table[contains(@id,'Field')]//tr[td//span[text()='Code']]/preceding-sibling::*[1]/td//select[contains(@id,'GSRCH_FLT')]/option[text()='not=']")).isDisplayed();

its returning false since it is not getting displayed in the box.

Can u tell me the alternative for this.

like image 487
Arun Avatar asked Dec 17 '12 06:12

Arun


1 Answers

You want:

private boolean isElementPresent(WebDriver driver, By by){
    return driver.findElements(by).count != 0;
}

findElements() is better for this than findElement() because it won't wait if the element isn't present. If you're running with implicit waits turned on, findElement() will time out looking for the element (that's the exception you're catching), and it will take a while.

like image 164
Ross Patterson Avatar answered Sep 29 '22 01:09

Ross Patterson