1

I am trying to find if the button element is clickable which I am not able to validate successfully using selenium webdriver.

Here is my code to validate if the element is clickable

    boolean installAFile;

    String classValues = driver.findElement(by.XPATH("//button[contains(., 'Install a new file')]")).getAttribute("class");
    installAFIle = classValues.contains("iconbutton-button--clickable");

    return installAFIle;

Here is the HTML

<div>
<!-- react-text: 406 -->
test message 1
<!-- /react-text -->
<div class="iconbutton">
<button class="iconbutton-button iconbutton-button--clickable" type="button" 
tabindex="0">
<div class="iconbutton-button-label">Install a new file</div>
</button>
</div>
<!-- react-text: 410 -->
under File > Install.
<!-- /react-text -->
</div>

I keep on getting following validation message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[contains(., 'Install a new file')]"}

8
  • Hi try using selenium wait condition.Please look this link stackoverflow.com/questions/12858972/…enter link description here Commented Jul 5, 2017 at 5:31
  • This may help stackoverflow.com/a/38327476/6743203 Commented Jul 5, 2017 at 5:36
  • In xpath, string is case sensitive. please check the string 'Install a new file' for the case. Commented Jul 5, 2017 at 5:39
  • @zen thanks for the suggestion, I have implemented te wait as well but still no luck Commented Jul 5, 2017 at 5:43
  • @SujaiKrishna A link is always a LINK which must be clickable. Hence your question makes no sense to me. Can you update the Question with your exact usecase and manual steps you are trying to perform? Thanks Commented Jul 5, 2017 at 6:09

2 Answers 2

6

Just write the below method and call it whenever you want to check whether element is clickable or not. Pass the required arguments also.

public static boolean isClickable(WebElement el, WebDriver driver) 
    {
        try{
            WebDriverWait wait = new WebDriverWait(driver, 6);
            wait.until(ExpectedConditions.elementToBeClickable(el));
            return true;
        }
        catch (Exception e){
            return false;
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

1

Element xpath will be;

/html/body/div/div/button/div

Or

//button/div

Or

//div[contains(@class,'iconbutton-button-label')]

Or

//*[contains(text(), 'Install a new file')]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.