Reputation: 1
i am trying to Automate flipkart website in which i am trying to change address but "add new adress" is not getting clicked i have attached the snapshot
my code is like driver.findElement(By.xpath("//*[@id='ng-app']/div/div[2]/ul/li[2]/div/div[2]/div[2]/div[2]/a/span")).click();
please give the appropriate help
Upvotes: 0
Views: 4492
Reputation: 1
First and foremost, Use a customized Xpath instead of the one you are using which is extracted directly from the browser. If no customized Xpath can be constructed then try a customized Css or any other locator if possible.
Try to go through the following attempts in order (I hope you can grasp why this is):
1- If .click()
still doesn’t work, then keep on changing the values of the attributes you are using to construct your customized xpath, cssSelector, or locator.
2- Use the Actions class.
3- Use JavaScript executioner
4- instead of click()
, try using any of: .sendKeys(“\n”).
Or .sendKeys(keys.ENTER)
or .sendKeys(keys.RETURN)
Upvotes: 0
Reputation: 1110
I doesn't look that you are clicking active element, the xpath is //*[@id='ng-app']/div/div[2]/ul/li[2]/div/div[2]/div[2]/div[2]/a/span
not correct it clicks on some span.
Use Firepath https://addons.mozilla.org/en-US/firefox/addon/firepath/ to get the xpath.
Upvotes: 1
Reputation: 644
To ensure that button is clickable Use isDisplayed()
and isEnabled()
method before clicking on "Add New Address" button, this method return boolean value.
driver.findElement(By.xpath("//*[@id='ng-app']/div/div[2]/ul/li[2]/div/div[2]/div[2]/div[2]/a/span")).isDisplayed();
driver.findElement(By.xpath("//*[@id='ng-app']/div/div[2]/ul/li[2]/div/div[2]/div[2]/div[2]/a/span")).isEnabled();
Also you can verify that element is exist on page or not using below code
if(driver.findElements(byVal).size()!=0){
// Element is present.
}
hope it may helpful to identify cause of issue, why its not clickable.
Upvotes: 0