3

I am trying to click Add New button. But it is throwing an error, saying org.openqa.selenium.ElementNotVisibleException: element not interactable

<div id="left-tabs-example-pane-metastore" aria-labelledby="left-tabs-example-tab-metastore" role="tabpanel" aria-hidden="false" class="fade tab-pane active in">
   <div class="title col-sm-12"><button class="custom-btn create-new-button" style="float: right;">Add New</button></div>
   <div class="test_table custom-test_table">
      <div class="divTable">
         <div class="divTableHeading">
            <div class="row" style="margin: 0px 3px; border-bottom: 1px solid rgb(221, 221, 221); padding: 15px;">
               <div class="col-sm-3">Name</div>
               <div class="col-sm-3">Created by</div>
               <div class="col-sm-3">Created on</div>
               <div class="col-sm-2">Status</div>
               <div class="col-sm-1">Actions</div>
            </div>
         </div>
         <div class="divTableBody">
            <div class="row" style="margin: 0px 3px; border-bottom: 1px solid rgb(221, 221, 221); padding: 15px;">
               <div class="col-md-3" title="beta-stage-metastore" style="text-overflow: ellipsis; display: inline-block; white-space: nowrap; overflow: hidden;"><a href="#/projects/p-b48010e4-873a-4c4b-9c71-10235dfc8cf0/resources/rds-3e5e6b92-0d59-4485-bf7a-e6965eb7f9f8/details">beta-stage-metastore</a></div>
               <div class="col-md-3">betaorg-admin</div>
               <div class="col-md-3">9th February at 13:17 hrs</div>
               <div class="col-md-2" style="overflow-wrap: break-word;">STOPPED</div>
               <div class="col-sm-1">
                  <span class="dropdown custom_dropdown option-custom_dropdown" style="border-right: none;">
                     <a href="" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><img src="images/more.png"></a>
                     <ul class="dropdown-menu">
                        <li><a>Start</a></li>
                     </ul>
                  </span>
               </div>
            </div>
         </div>
      </div>
   </div>
</div>

I have tried following:

driver.findElement(By.cssSelector(".custom-btn.create-new-button")).click();

Xpath for Add New button generated using chrome extension is:

/html/body/div[@id='app']/div[@class='_loading-overlay']/main/div[@class='container-fluid search_table_container']/div[@class='col-md-12 test_tab_wrapper']/div[@class='test_subtab_container']/div[@id='left-tabs-example']/div[@class='col-sm-12'][2]/div[@class='tab-content']/div[@id='left-tabs-example-pane-resources']/div/div[@class='workflowtab_box']/div[@class='row vertical_tab_panel_container']/div[@id='left-tabs-example']/div[@class='col-sm-9']/div[@class='tab-content']/div[@id='left-tabs-example-pane-metastore']/div[@class='title col-sm-12']/button[@class='custom-btn create-new-button']
2
  • Can you check if the button is in an iframe ? Commented Feb 9, 2019 at 17:48
  • Have answered it, please check and let me know if that helps. Commented Feb 9, 2019 at 17:59

4 Answers 4

1

Basically, there are four reasons why an element is not interactable.

1) Timing - the time it takes for elements to load. For this, you need to check how to use implicit an explicit wait

2)Check if the element is in a frame. For this, switch to the frame.

3) Incorrect locator

4) Wrong implementation of responsiveness. This still stems from no 3). Some websites have only one code turned on for mobile and web versions. So, the element will have more than one instance when you check the xxxxx.size. You will have to search through the list for the one whose display != none. Then, you can append the position of the element to your xpath or whatever locator you are using. E.g. xxxx/yyyyy/zzzz[3] if the position is 4 in the list.

Use this code for java, Assumptions a)the locator type is id b)name of the list is nameOfYourElements

List nameOfYourElements = wd.findElements(By.id("nameOfYourID")); System.out.println(nameOfYourElements.size());

Sign up to request clarification or add additional context in comments.

Comments

0

To click on the element with text as Add New you can use either of the following solutions:

  • cssSelector:

    driver.findElement(By.cssSelector("div.tab-content>div#left-tabs-example-pane-metastore>div.title>button.custom-btn create-new-button")).click();
    
  • xpath:

    driver.findElement(By.xpath("//div[@class='tab-content']/div[@id='left-tabs-example-pane-metastore']/div[contains(@class, 'title')]/button[@class='custom-btn.create-new-button' and text()='Add New']")).click();
    

7 Comments

for cssSelector it said:org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element for xpath it said: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:
Everything else works correctly on that page, just Add New button is not working
I tried following and it worked: //div[@class='tab-content']/div[@id='left-tabs-example-pane-metastore']/div[@class='title col-sm-12']/button[@class='custom-btn create-new-button']
Gimme a minute, let me check the difference
@user10144071 The parent node //div[@class='tab-content'] is still not a part of the html which you have provided us :) I have updated my answer as per your comments. Let me know the status please.
|
0

Please give some wait time to webdriver to visible the element.Please try this.

    WebDriverWait wait = new WebDriverWait(driver, 40);          
 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/button[@class='custom-btn create-new-button']"))).click();

7 Comments

not working is says org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: //button[@class='custom-btn create-new-button'] (tried for 40 second(s)
Strange.why it is not working at your machine.It is working in my machine.I have tested and then forwarded.
Don't know why. that button as you see in html is inside two div tag
Error says timeoutexception
didnot worked. I have updated the question. please check last time
|
0

Try the xpath: driver.findElement(By.xpath("//button[text()='Add New']"));

Please check if the element is in an iframe or not. If yes, then you need to first switch to the iframe and then click on the element, for switching to the iframe, you can refer to: How to handle iframe in Selenium WebDriver using java

If its not in an iframe then you can directly click on the element using the above mentioned xpath.

12 Comments

Ok, then please try the xpath i have mentioned, it should help you
didn't work i tried: driver.findElement(By.xpath("//button[contains(@class='custom-btn create-new-button')]")); It says org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //button[contains(@class='custom-btn create-new-button')]
Thats the wrong xpath that you have mentioned here, with contains, xpath doesnt include =, so please try the one i have mentioned in the answer and let me know if that works.
i tried this: driver.findElement(By.xpath("//button[contains(@class,'custom-btn create-new-button')]")).click(); It says, org.openqa.selenium.ElementNotVisibleException: element not interactable
Ok, have edited the xpath in the answer, please try that one too, might help you :)
|

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.