Avinash Jadhav
Avinash Jadhav

Reputation: 1393

Not able to click on WebElement

In selenium I am getting web element which i want to select WebElement.IsDisplayed() return true but i am not able to perform webelement.click() operation.

 port_dimension = canvas.find( By.xpath( "//*[local-name() = 'rect'][@visibility='visible' and @height = '22']" ) ); //$NON-NLS-1$
 port_dimension.getElement().click();

Upvotes: 0

Views: 496

Answers (2)

Shubham Jain
Shubham Jain

Reputation: 17553

You can also click using JavascriptExecutor

  WebElement element=driver.findElement(By.xpath("//*[local-name() = 'rect'][@visibility='visible' and @height = '22']"));
  JavascriptExecutor executor = (JavascriptExecutor) driver;
  executor.executeScript("arguments[0].click();", element);

Now I am predicting the your xpath is fine and In some cases wait is needed so put wait if you are still facing issue. so

njoy ... get back to me if still facing issue :)

Upvotes: 1

giri-sh
giri-sh

Reputation: 6962

You can also click on the WebElement without using getElement() function. Here's how -

driver.findElement(By.xpath("//*[local-name() = 'rect'][@visibility='visible' and @height = '22']")).click();

If your xpath locator is working as required then the element should be clicked. If you still are getting some issue, then probably add a sleep event with Thread.sleep(5000); before click action. Hope this helps.

Upvotes: 1

Related Questions