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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With