1

Not able to click Search button and also select the option from the drop down Getting:

org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with

Reason: After selecting the value from the dropdown list the cursor remains in the dropdown text box and is not going to the Search button

Can someone please let me know what can be done

WebElement Searchbox = driver.findElement(By.xpath("//span[contains(normalize-space(),'Search')]/preceding::button[contains(@onclick,'mainForm:messages2')]"));
WebDriverWait wait = new WebDriverWait(driver,50); 
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(normalize-space(),'Search')]/preceding::button[contains(@onclick,'mainForm:messages2')]")));

Searchbox.click();

below is the Html code: - I am trying to click on the Search button

<td role="gridcell" class="ui-panelgrid-cell" colspan="2">
   <button id="mainForm:j_idt441" name="mainForm:j_idt441" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" 
           onclick="PrimeFaces.ab({s:&quot;mainForm:j_idt441&quot;,u:
                    &quot;mainForm:projectG
                    groupsTable mainForm:messages2&quot;});
                    return false;" type="submit" role="button" aria-disabled="false">
      <span class="ui-button-text ui-c">Search</span>
   </button>
</td>
5
  • instead of saying it didn't work and you tried , please add what was the error and what code you have tried – PDHide Feb 5 at 11:04
  • Kindly check the error that I have already added above:org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with... Code: – sandy Feb 5 at 11:44
  • WebElement Searchbox = driver.findElement(By.xpath("//span[contains(normalize-space(),'Search')]/preceding::button[contains(@onclick,'mainForm:messages2')]")); WebDriverWait wait = new WebDriverWait(driver,50); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(normalize-space(),'Search')]/preceding::button[contains(@onclick,'mainForm:messages2')]"))); Searchbox.click(); – sandy Feb 5 at 11:44
  • ((JavascriptExecutor) driver).executeScript( // "arguments[0].scrollIntoView(true);", Searchbox); – sandy Feb 5 at 11:44
  • Actions action = new Actions(driver); action.movetoElement(Searchbox).click.perform(); – sandy Feb 5 at 11:44
1
WebElement Searchbox = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(),'Search')]/ancestor::button")));

Searchbox.click();

webdriver wait returns the element , so don't find it before using wait . ALso change normalize text to text() or string()

15
  • Thank you for the inputs will try and revert – sandy Feb 5 at 12:06
  • No Luck still got the same issue org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with..... – sandy Feb 5 at 12:17
  • @sandy //span[contains(text(),'Search')]/ancestor::button – PDHide Feb 5 at 12:24
  • use this locator button is not preceeding element but ancestor for the html you have provided – PDHide Feb 5 at 12:24
  • No luck tried with the xpath that you have given since there are 3 search button took the position of the Search button that needs to be clicked...(//span[contains(text(),'Search')]/ancestor::button)[2] – sandy Feb 5 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.