From: <r.b...@af...> - 2016-03-18 11:04:37
|
SOLVED! .. I just added browser.waitForBackgroundJavaScript(8000); after page = (HtmlPage) search_submit.click();.. thanks ! -----Messaggio originale----- Da: r.b...@af... [mailto:r.b...@af...] Inviato: venerdì 18 marzo 2016 11:20 A: htm...@li... Oggetto: [Htmlunit-user] Cannot select dynamic selection Hi, how can I select the field "Search By" in this site with HTmlUnit? : http://web.molpower.com/NaviGator/Tracking/home the field is not a normal tag This is my code : String searchLink = "http://web.molpower.com/NaviGator/Tracking/home"; System.out.println(" searchLink BN : [" + searchLink + "]"); HtmlPage page = (HtmlPage) browser.getPage(searchLink); // <input id="SearchBy" class="valid" type="text" style="width: 100%; display: none;" name="SearchBy" data-role="dropdownlist"> String xpath = "//input[contains(@id, 'SearchBy')]"; HtmlInput input_select = (HtmlInput) page.getFirstByXPath(xpath); input_select.setValueAttribute("BKG"); // <textarea id="SearchString" class="valid" style="width:500px;height:75px;" spellcheck="false" rows="2" name="SearchString" cols="20"></textarea> xpath = "//textarea[contains(@id, 'SearchString')]"; HtmlTextArea input_area = (HtmlTextArea) page.getFirstByXPath(xpath); input_area.setText("28010665376A"); // booking number System.out.println("input_area : [" + input_area.asXml() + "]"); // <input id="btnSearch" class="k-button" type="submit" value="Search"> xpath = "//input[contains(@id, 'btnSearch')]"; HtmlSubmitInput search_submit = (HtmlSubmitInput) page.getFirstByXPath(xpath); HtmlUnorderedList ul = (HtmlUnorderedList) page.getElementById("SearchBy_listbox"); List<HtmlListItem> listLi = (List<HtmlListItem>) page.getByXPath(ul.getCanonicalXPath() + "/li"); // Get the default selected li element HtmlListItem liDefault = listLi.get(0); System.out.println("Default item selected : [" + liDefault.asXml() + "]"); for (HtmlListItem li : listLi) { // Select "Booking" if (li.asXml().contains("Booking")) { System.out.println("Booking : [" + li.asXml() + "]"); li.setAttribute("aria-selected", "true"); li.setAttribute("class", "k-item k-state-selected k-state-focused"); li.setAttribute("id", "SearchBy_option_selected"); liDefault.setAttribute("class", "k-item"); liDefault.removeAttribute("id"); liDefault.removeAttribute("aria-selected"); } } page = (HtmlPage) search_submit.click(); I cannot get the result page but the same search page.. Thanks. Roberto Bottoni -------------------------------------------- AfterBit s.r.l. Via Valdera P, 67 - 56038 Ponsacco (Pisa) - ITALY Tel. +39 0587 734173 Fax. +39 0587 734173 E-mail : r.b...@af... - Internet : www.afterbit.com ---------------------------------------------------------------------------- -- Transform Data into Opportunity. Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library. Click to learn more. http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140 _______________________________________________ Htmlunit-user mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/htmlunit-user |