java - How to verify presence of a text in a row. (Assert vs Verify) -
my application creates new row in table whenever new case added in application. row has few columns , content of column can similar of other columns. need find if "text" present in row. below code:
@test (priority = 2) public void savestatus() { webelement element = driver.findelement(by.partiallinktext("case listing")); //to find 'case listing' button on dashboard actions action = new actions (driver); action.movetoelement(element); //move mouse , hover 'case listing' button action.click().build().perform(); //click on 'case listing' button list<webelement> newcase = driver.findelements(by.xpath("//*[@id='caselist']/tbody/tr[1]"));//find new case saved in caselist string casestatus = ((webelement) newcase).gettext(); if (casestatus.contains("draft")){ assert.asserttrue(istextpresent("draft")); } system.out.println("test case 3 --> case status draft");
i need verify presence of text "draft" in row. text appear in 4 column. other rows can have similar text hence don't want use getpagesource().contains
. error i'm getting:
java.util.arraylist cannot cast org.openqa.selenium.webelement
issue occuring @ below line, using gettext() webelements. applicable type webelement.
string casestatus = ((webelement) newcase).gettext();
you need use loop loop through webelements in list , verify text.
example:assuming id of table caselist
webelement table_element = driver.findelement(by.id("caselist")); list<webelement> tr_collection=table_element.findelements(by.xpath("//*[@id='caselist']/tbody/tr")); system.out.println("number of rows in table = "+tr_collection.size()); int row_num,col_num; row_num=1; for(webelement trelement : tr_collection) { list<webelement> td_collection=trelement.findelements(by.xpath("td")); system.out.println("number of columns="+td_collection.size()); col_num=1; for(webelement tdelement : td_collection) { system.out.println("row # "+row_num+", col # "+col_num+ "text="+tdelement.gettext()); col_num++; } row_num++; }
you can write verify step above or below of syso statement.
system.out.println("row # "+row_num+", col # "+col_num+ "text="+tdelement.gettext()); if (tdelement.gettext().contains("draft")){ // }
Comments
Post a Comment