Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys,

Thanks in advance for helping me out!
I am trying to automate a search on a specific website. But when I "click the button", no results are returned.

Some website code:

<div class="form-search" data-prop-type="rgu" data-prop-ajaxsearch="false" data-prop-ajaxsearch-question="" data-prop-typeahead="true" data-prop-typeahead-minlength="2" data-prop-typeahead-maxlength="25" data-prop-typeahead-cache="true" data-prop-typeahead-url="/ajax/jsp/typeAheadRequest.jsp" data-prop-typeahead-loader="" data-prop-searchactionurl="/searchpage/">

<form id="searchForm" name="searchForm" action="/searchpage/?_DARGS=/blocks/header/search.jsp.searchForm" class="search-submit-form" method="post"><input name="_dyncharset" value="utf-8" type="hidden"><input name="_dynSessConf" value="6919835643130731016" type="hidden">
          
<input id="s_search" name="s_search" value="" class="hidden" type="submit" data-action="search-query-hidden-formsubmit"><input name="_D:s_search" value=" " type="hidden">
        
<input id="s_paging" name="s_paging" value="" class="hidden" type="submit" data-action="search-paging-hidden-formsubmit"><input name="_D:s_paging" value=" " type="hidden">

<fieldset><p>
            
<input type="submit" name="submitSearchBTN" id="submitSearchBTN" value="Zoeken" class="search" data-action="init-search">

<input type="submit" class="visual-search" id="submitVisualSearchBTN" name="visual-search" title="Zoeken met afbeeldingen" data-action="search-query-setzma" data-prop-question="" data-prop-zmasearch="true" data-track-action="Blader en zoek" data-track="Start zoeken met afbeeldingen">
            
</p></fieldset>
        
<input name="_DARGS" value="/blocks/header/search.jsp.searchForm" type="hidden"></form>


I want to search to search results page, but a default company website page, without search results is returned. Does this error has anything to do with the "AJAX" components on the website?

Does anybody know how I can get actual results back?
Thank you very much!

What I have tried:

HtmlForm searchForm = (HtmlForm) page.getElementById("searchForm");
        
// Get the input field
HtmlTextInput searchInput = (HtmlTextInput) page.getElementById("searchQuestionIP");

// Insert the search term
searchInput.setText("dummy");

// searchInput.setValueAttribute("dummy");
// Workaround: create a 'fake' button and add it to the form

HtmlButton submitButton = (HtmlButton) page.createElement("button");
submitButton.setAttribute("type", "submit");
searchForm.appendChild(submitButton);

// Workaround: use the reference to the button to submit the form.

page = submitButton.click();
 
// webClient.waitForBackgroundJavaScript(10000);
      
System.out.println(page.asXml());

// I also tried:
//HtmlTextInput searchInput = (HtmlTextInput) page.getElementById("searchQuestionIP");

//searchInput.setText("dummy");
//HtmlElement gg = (HtmlElement) page.getElementById("submitSearchBTN");
//page = gg.click();
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900