Sushant Tavrawala
Sushant Tavrawala

Reputation: 55

This XPath expression is not working with Selenium WebDriver

I am using Google Chrome as webdriver.

The Sign Up button code is:

<button type="submit" class="signupbtn btn_full btn btn-action btn-block btn-lg">
    <span class="ink animate" style="height: 488px; width: 488px; top: -215px; left: -118px;"></span>
    <i class="fa fa-check-square-o"></i>
    Sign Up
</button>

The error code is:

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (681, 658)

My XPath code for execution is:

driver.findElement(By.xpath("//*@id='headersignupform']/div[9]/button")).click();

However, it is not executing the script and is throwing the above error. As you can see, in the console it is locating the button with my code in the console.

Enter image description here

Upvotes: 1

Views: 3822

Answers (3)

Aarya Hareendranath
Aarya Hareendranath

Reputation: 370

You could use an action class for the same:

WebElement element = driver.findElement(By.xpath("//*[@id='headersignupform']/div[9]/button"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().perform();

The second thing is it's always advisable to use an exact tag instead of *[@id =""].

Upvotes: 0

undetected Selenium
undetected Selenium

Reputation: 193088

It seems the Sign Up button has an overlay. So to interact directly with the Sign Up button, we need to use the help of JavascriptExecutor as follows:

WebElement button = driver.findElement(By.xpath("//button[@class='signupbtn btn_full btn btn-action btn-block btn-lg']"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].click();", button);

Upvotes: 2

Shubham Jain
Shubham Jain

Reputation: 17553

You need to use focus or scroll to that element. You also might have to use an explicit wait.

WebElement element = driver.findElement(By.xpath("//*@id='headersignupform']/div[9]/button"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();

If it still does not work, use JavascriptExecutor:

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);

Upvotes: 2

Related Questions