java - Selenium: Element not getting child element -
i doing selenium automation test list of webelements child elements of each of of them. unfortunately when it, gets child elements of first element list weird. can point on went wrong? thanks.
@override public void performtest() { performaction(); try { (webelement element : search_rows) { system.out.println(element.getattribute("class")); system.out.println(element); assertelements(element, constants.selectors.amity_result_one); assertelements(element, constants.selectors.amity_result_two); assertelements(element, constants.selectors.amity_result_three); } webelement nextpage = webdriverutils.findelementbycssselector( driver, constants.selectors.amity_next_page); webdriverutils.scrolltoelement(driver, nextpage, webdriverutils.by_javascript); nextpage.click(); performtest(); } catch (exception e) { // e.printstacktrace(); } } @override public void performaction() { try { webelement searchpage = webdriverutils.findelementbyxpath(driver, constants.selectors.amity_searched_items); search_rows = searchpage.findelements(by .xpath(constants.selectors.amity_search_wrapper)); } catch (exception e) { // e.printstacktrace(); } } private void assertelements(webelement element, string constant) { search_result = element.findelement(by.xpath(constant)); system.out.println(search_result.getattribute("class")); system.out.println(search_result); system.out.println(search_result.findelement(by .xpath(constants.selectors.amity_first_choice))); comparetext = search_result.findelement( by.xpath(constants.selectors.amity_first_choice)).gettext(); comparetext(combo.getbeds(), comparetext); system.out.println(search_result.findelement(by .xpath(constants.selectors.amity_second_choice))); comparetext = search_result.findelement( by.xpath(constants.selectors.amity_second_choice)).gettext(); comparetext(combo.getbaths(), comparetext); system.out.println(search_result.findelement(by .xpath(constants.selectors.amity_third_choice))); comparetext = search_result.findelement( by.xpath(constants.selectors.amity_third_choice)).gettext(); comparetext(combo.getcarparks(), comparetext); system.out.println(search_result.findelement(by .xpath(constants.selectors.amity_name))); comparetext = search_result.findelement( by.xpath(constants.selectors.amity_name)).gettext(); containstext(combo.getsuburb(), comparetext); if (combo.getprice() != null) { system.out.println(search_result.findelement(by .xpath(constants.selectors.amity_price))); comparetext = search_result.findelement( by.xpath(constants.selectors.amity_price)).gettext(); if (!comparetext.equals("contact agent")) { comparetext = parseprice(comparetext); compareprice(combo.getprice().substring(2), comparetext); } } }
here constants:
public static final string amity_searched_items = "//div[@class='content-sidebar-wrap']"; public static final string amity_search_wrapper = "//div[@class='searches-wrapper']"; public static final string amity_result_one = "//div[contains(@class, 'searchresultbox1')]"; public static final string amity_result_two = "//div[contains(@class, 'searchresultbox2')]"; public static final string amity_result_three = "//div[contains(@class, 'searchresultbox3')]"; public static final string amity_first_choice = "(//div[@class='searchinfo']//span)[1]"; public static final string amity_second_choice = "(//div[@class='searchinfo']//span)[2]"; public static final string amity_third_choice = "(//div[@class='searchinfo']//span)[3]"; public static final string amity_name = "//p[@class='p-searchname']"; public static final string amity_price = "//div[@class='search-wrapp']//div[@class='searchprice']//span[@class='spn-search-price']//span[@class='searchprice']"; public static final string amity_next_page = ".pagination-next > a:nth-child(1)";
thank you. need solve quickly
xpath beginning //
global, if execute context of element.
try using .//
instead limit element's children.
Comments
Post a Comment