how can check if new appending element's text equal string? want find word in chat, looks pointing same element.
while (true){ try { webdriverwait wait = new webdriverwait(driver, 5); wait.until(expectedconditions.texttobepresentinelementlocated(by.xpath("//span[@class='msg-body']"), "hello")); system.out.println("found hello"); } catch (exception e) { system.out.println("nothing found"); } thread.sleep(100); }
the part of chat html
<li class="msg-chat-message"> <span class="user role-user"> <img class="user-logo" src="https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/d6/d6e4e034324f1e2abe161a8239f243a2f48e08e9.jpg"> <div class="user-level-container"> <div class="user-level level-item level-70">75</div> </div> <span class="drop-down-container _3_options"> <ul class="user-dropdown-invisible"> <li class="user-dropdown-entry">stats</li> <li class="user-dropdown-entry">tip</li> <li class="user-dropdown-entry">ignore</li> <!-- react-text: 928 --> <!-- /react-text --> </ul> </span> <span class="user-name"> <span> <!-- react-text: 931 -->repo <!-- /react-text --> <span class="icon-balanceicon namepromotion" title="this user has activated name promotion"></span> <!-- react-text: 933 --> <!-- /react-text --> </span> <!-- react-text: 934 -->: <!-- /react-text --> </span> </span> <span class="msg-body">all of you</span> </li> <li class="msg-chat-message"> <span class="user role-user"> <img class="user-logo" src="https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/1a/1a5e80deb58be484e49ea9a9434faa7a6528654b.jpg"> <div class="user-level-container"> <div class="user-level level-item level-50">50</div> </div> <span class="drop-down-container _3_options"> <ul class="user-dropdown-invisible"> <li class="user-dropdown-entry">stats</li> <li class="user-dropdown-entry">tip</li> <li class="user-dropdown-entry">ignore</li> <!-- react-text: 946 --> <!-- /react-text --> </ul> </span> <span class="user-name"> <span> <!-- react-text: 949 -->anonymous <!-- /react-text --> <span class="icon-balanceicon namepromotion" title="this user has activated name promotion"></span> <!-- react-text: 951 --> 3 <!-- /react-text --> </span> <!-- react-text: 952 -->: <!-- /react-text --> </span> </span> <span class="msg-body">kk</span> </li> <li class="msg-chat-message"> <span class="user role-user"> <img class="user-logo" src="https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/44/44c705474e17ebe8a2a9ef70467c20ee5add283e.jpg"> <div class="user-level-container"> <div class="user-level level-item level-50">52</div> </div> <span class="drop-down-container _3_options"> <ul class="user-dropdown-invisible"> <li class="user-dropdown-entry">stats</li> <li class="user-dropdown-entry">tip</li> <li class="user-dropdown-entry">ignore</li> <!-- react-text: 964 --> <!-- /react-text --> </ul> </span> <span class="user-name"> <span> <!-- react-text: 967 -->rrubinski. em <!-- /react-text --> <span class="icon-balanceicon namepromotion" title="this user has activated name promotion"></span> <!-- react-text: 969 --> <!-- /react-text --> </span> <!-- react-text: 970 -->: <!-- /react-text --> </span> </span> <span class="msg-body">which 1 u want?</span> </li>
so far created list of elements, it's size equal 400 items (when chat filled messages); still want know if possible track new elements instead of looping 400 times.
elementlist = driver.findelements(by.xpath("//span[@class='msg-body']")); (webelement element: elementlist) { if (element.gettext().equals("nice")) { system.out.println("done"); system.out.println("list size: " + elementlist.size()); } } thread.sleep(200);
kindly check let me know.
i assume message appended automatically in dom same class similar as,
<span class="msg-body">which 1 u want?</span>
and objective text of last appended message. can know number of instances of messages , text of last one.
int size = driver.findelements(by.xpath("//span[@class='msg-body']")).size();
now text of last message.
string message = driver.findelement(by.xpath("//span[@class='msg-body'][" + size + "]")).gettext();
later user java api's or testng methods validation of string message.
hope helps. thanks.
Comments
Post a Comment