0

Here is my HTML code,

<div class="input-group-btn search-panel dropdown open">
<input type="search" id="footerSearch" class="form-control search-input search-filter-component" name="x" placeholder="Search term...">
<span class="input-group-btn gosearch-btn">
        <button class="btn  search-filter-component" type="button"><span class="glyphicon glyphicon-search"></span></button>
    </span>

I am getting below error, Exception in thread "main"

org.openqa.selenium.NoSuchElementException:
Element info: {Using=xpath, value=//span[@class='input-group-btn gosearch-btn']}
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:473)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:360)
    at PncSite.EnterSite.main(EnterSite.java:35)

Thanks for your update. I tried with your xpath,but it's not working. It's displaying the same error.

Here is the HTML code and screenshot.

<div id="cssearch_nav" class="input-group searchfilter-group">
    <div class="input-group-btn search-panel dropdown">
        <button type="button" class="btn dropdown-toggle search-filter-component" data-toggle="dropdown">
            <span id="search_concept">Customer</span>
            <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu"> 
            <li class="dropdown-menu-item">
                <a data-autocomplete="false" class="search-filter active-filter" id="customerNameFilter">Customer</a>
            </li>

            <script>
            $(document).ready(function() 
            {
                var eleId = 'customerNameFilter';
                var searchTmpId = '504417871974215089';
                var screenUrl = '/wbs/template/customer.jsp';
                var searchField = 'customer.company_name_uc';
                var parInputGroup= $("#"+eleId).parents("div.input-group:first");

                if(parInputGroup!=undefined &&parInputGroup.length>0)
                {
                    var parId = $(parInputGroup).attr("id");
                    window[parId].addSearchFilter(eleId,searchField,searchTmpId,screenUrl);
                }
            });
            </script>
            <li class="dropdown-menu-item">
                <a data-autocomplete="false" class="search-filter" id="customerFilter">Customer No.</a>
            </li>

            <script>
            $(document).ready(function() 
            {
                var eleId = 'customerFilter';
                var searchTmpId = '504417871974215089';
                var screenUrl = '/wbs/template/customer.jsp';
                var searchField = 'customer.entity_no';
                var parInputGroup= $("#"+eleId).parents("div.input-group:first");

                if(parInputGroup!=undefined &&parInputGroup.length>0)
                {
                    var parId = $(parInputGroup).attr("id");
                    window[parId].addSearchFilter(eleId,searchField,searchTmpId,screenUrl);
                }
            });
            </script>
            <!--   FR Search -->
            <li class="dropdown-menu-item">
                <a data-autocomplete="false" class="search-filter" id="finreqFilter">Request No.</a>
            </li>

            <script>
            $(document).ready(function() 
            {
                var eleId = 'finreqFilter';
                var searchTmpId = '2993108337328648426';
                var screenUrl = '/wbs/template/finance_request.jsp';
                var searchField = 'finance_request.entity_no';
                var parInputGroup= $("#"+eleId).parents("div.input-group:first");

                if(parInputGroup!=undefined &&parInputGroup.length>0)
                {
                    var parId = $(parInputGroup).attr("id");
                    window[parId].addSearchFilter(eleId,searchField,searchTmpId,screenUrl);
                }
            });
            </script>
            <li class="dropdown-menu-item">
                <a data-autocomplete="false" class="search-filter" id="trxFilter">Transaction No.</a>
            </li>

            <script>
            $(document).ready(function() 
            {
                var eleId = 'trxFilter';
                var searchTmpId = '7785538818744716350';
                var screenUrl = '/wbs/template/financial_trx_details.jsp';
                var searchField = 'financial_trx.entity_no';
                var parInputGroup= $("#"+eleId).parents("div.input-group:first");

                if(parInputGroup!=undefined &&parInputGroup.length>0)
                {
                    var parId = $(parInputGroup).attr("id");
                    window[parId].addSearchFilter(eleId,searchField,searchTmpId,screenUrl);
                }
            });
            </script>
            <!--   Quote Search -->

        </ul>
    </div>
    <input type="search" id="footerSearch" class="form-control search-input search-filter-component" name="x" placeholder="Search term...">
    <span class="input-group-btn gosearch-btn">
        <button class="btn  search-filter-component" type="button"><span class="glyphicon glyphicon-search"></span></button>
    </span>
</div>
  • Can you please share your HTML code or screenshots . – shanila Sep 27 '18 at 9:56
  • Share your code that you have tried – Alok Sep 29 '18 at 17:37
  • Here is the code that I used,driver.findElement(By.xpath("//div[@class='input-group-btn search-panel dropdown open']")); Thread.sleep(6000); driver.findElement(By.xpath("//span[@id='search_concept']")); Thread.sleep(5000); System.out.println("Performing Footer Search"); System.out.println("For Entering Text"); driver.findElement(By.xpath("//input[@id='footerSearch']")).sendKeys("Lex G"); System.out.println("Clicking Search Icon"); driver.findElement(By.xpath("//input[@id='footerSearch']/following-sibling::span[@class='input-group-btn gosearch-btn']")).click(); – Sathiya Priya Oct 9 '18 at 13:26
  • Please correct it,if there is any errors – Sathiya Priya Oct 9 '18 at 13:26
0

As per the HTML code provided above, it seems like search textbox is inside the expanded drop-down. So we have to make sure drop-down remains opened while locating the 'Search' element.

You can use below-mentioned locators that we usually use in automation testing. As per our understanding from HTML code, you can use below locators:

For entering Text:

driver.findElement(By.xpath("//input[@id='footerSearch']").sendKeys("searchText");

Click Search icon:

driver.findElement(By.xpath("//input[@id='footerSearch']/following-sibling::span[@class='input-group-btn gosearch-btn']").click();

Hope your issue will be resolved. Further, if you still face any issue please provide screenshots of UI with HTML code of drop-down, so that we can provide more inputs.

  • Hi Kannathasan,Thanks for your update.I tired with your xpath,but its not working.Its again displays same error.Here is the – Sathiya Priya Sep 28 '18 at 7:19
0
  • Please make sure that the drop-down menu is opened while you try to enter the Search Text
  • Try to add the Thread.sleep() after the pressing the drop-down menu, sometimes the menu can be opened with the delay, so a driver can't find an element
  • Did the driver enter the search text in the search field?

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.