Skip to content
Advertisement

Unable to click a button in Selenium

I’m facing a tough time clicking a button from Selenium.

Here’s the DOM: http://pasteboard.co/GHIjMd6.png

I’ve declared the button WebElement this way using Xpath (a valid Xpath that returns one node as per Firepath):

WebElement send_this_msg_btn = driver.findElement(By.xpath("//*[@class='mp-button-content'][.='Send This Message']"));

I’ve tried clicking the said button with send_this_msg_btn Xpath in below mentioned ways, but none of them work for me.

WebDriver’s click() method : send_this_msg_btn.click()

JavaScriptExecutor:

JavaScriptExecutor jse = (JavaScriptExecutor)driver;
jse.executeScript("arguments[0].click();", send_this_msg_btn);

Actions class:

Actions actions = new Actions(driver);
actions.moveToElement(send_this_msg_btn);
actions.click();
actions.build().perform();

I also checked if the button is inside a frame/iframe, but that’s not the case either.

Advertisement

Answer

Changing the xpath to .//mp-button[@class='mp-button-primary submit_button'] resolved the issue, but I’m not sure if this should be the accepted answer since I’m not sure if it’s a fragile xpath. Any suggestions are welcome!

Advertisement