0
votes

My AUT have different tabs to test and validate various WebElements, having almost identical properties, present on these tabs. I need to validate a dropdown searchbox and validate the options listed in the dropdown. My script can not locate this dropdown searh box, while the xpath work perfectly fine in firebug and can identify the search box.

The error displayed is:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//div[@class='btn-group']/select[@id='selectBS']"}

My script is as below:

if(Driver.findElement(By.xpath("//div[@class='btn-group']/select[@id='selectBS']")).isDisplayed());
{
    System.out.println(" drop down box is displayed on the View Bill screen");
}

The HTML is as below:

<div class="col-md-5 col-sm-6 col-xs-12">
   <div class="row panel panel-default panel-heading">
      <div class="col-sm-4 col-xs-12">
         <div class="dropdown">
            <div class="btn-group">
               <select id="selectBS" class="ng-pristine ng-valid ng-touched" ng-change="getBasicSearchSelectedOption()" ng-model="basicSearchSelectedOption" ng-options="option.text for option in basicSearchoptions track by option.index">
                     <option value="0" selected="selected" label="Search For..">Search For..</option>
                     <option value="1" label="Invoice Group Number">Invoice Group Number</option>
                     <option value="2" label="Account Number">Account Number</option>
                     <option value="3" label="Account Name">Account Name</option>
                     <option value="4" label="Type">Type</option>
               </select>
           </div>
       </div>
   </div> 

Please let me know what could be wrong, and why Selenium is not able to locate the element using xpath, while its working fine in xpath. Also, please let me know if my xpath is not correct.

1
try to add few seconds of implicit wait for element to appear on pageAndersson
Hi Andersson, Thanks. I have already included implicit wait at the start of my script. Driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); Also I tried to add sleep thread before this snippet but it did not helped: try{ Thread.sleep(500); }catch(InterruptedException e){ e.printStackTrace(); }Atif
WebDriverWait wait = new WebDriverWait(driver, 20); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='btn-group']/select[@id='selectBS']")));Kishan Patel
Hi Andersson / Kishen, this does not helped me either. When I rerun the script its showing the below errors: First error: Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 20 seconds waiting for visibility of element located by By.xpath: //div[@class='btn-group']/select[@id='selectBS'] Second error: Unable to locate element: {"method":"xpath","selector":"//div[@class='btn-group']/select[@id='selectBS']"}.Atif

1 Answers

0
votes

Check if is present, after that, do some action so the options are visible and check that an option is visible. If these work then it may be an issue checking isDisplayed for elements with type select.