Reputation: 11
I'm trying to click search button on flipkart through Selenium Webdriver using Java, i'm able to click the button by the X-path and i written 'Boolean
' to display button was clicked.
Here's the code:
WebElement search = driver.findElement(By.xpath(".//*[@id='fk-header-search-form']/div/div/div[2]/input[1]"));
search.click();
boolean clicked = search.isEnabled();
System.out.println("Serach Button Clicked"+clicked);
Upvotes: 1
Views: 39
Reputation: 25644
There are a few issues.
.isEnabled()
Determines whether the element is enabled. According to the docs, this is pretty much always going to be true except in a case where there's an INPUT that is disabled (which doesn't apply here). So your code is just telling you that the Search button is not disabled, not whether you clicked it or not.
You didn't post enough code to tell why you are getting this error. I can see what you are trying to do and wrote a simple example of how to do this.
Try this
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.flipkart.com/");
By searchBoxLocator = By.id("fk-top-search-box");
By searchButtonLocator = By.cssSelector("input[value='Search']");
driver.findElement(searchBoxLocator).sendKeys("watch");
driver.findElement(searchButtonLocator).click();
Upvotes: 1
Reputation: 1583
If page is change after click on button, it is normal to not find element. You perform a search peocess, after click, new page being loading. Another point, isEnabled, everytime returns true except disabled. In this situation, it looks already active.
Upvotes: 1