Selenium : need help to locate element one class value -


<div id="sessions" class="container" style="display: block;">  <div id="usrsessionlist" class="list" style="height: 109px;">  <div class="alert alert-info emptylist" style="text-align: center; display: none;" data-i18n="emptysession">no existing session</div>  <div id="d37867bb-56be-10c0-3421-904ff75aae23" class="row tableheight">  <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 user">test12</div>  <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 opr"/>  <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 lstoprid"/>  <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 evt">usr_in</div>  </div>  <div id="6e1385ed-3027-2b84-9183-433139fde868" class="row tableheight">  <div id="96235b5d-c8b4-5310-6e8f-b247b17482a2" class="row tableheight">  <div id="a7bef619-31c6-c7a9-a4c3-33b8ee583d4d" class="row tableheight">  </div>  </div>  <div id="sessionconversation" style="display: none;">  </div>  </div>

i trying locate 'test12' using xpath. fail...

string expectedtext = "test12";
webelement name= driver2.findelement(by.xpath("//div[contains(text(),'"+expectedtext+"')]"));

can have other idea? much!

i write functions things because reused. example, looks looking user.

if in html section

<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 user">test12</div> <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 opr" /> <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 lstoprid" /> <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 evt">usr_in</div> 

you see 4 of these divs have same classes except last class, user. info, can create css selector find element. 1 way is

public webelement getusername() {     return driver.findelement(by.cssselector("div.user")); } 

which returns webelement contains user's name. use like

system.out.println(getusername().gettext()); 

one problem if there bunch of blocks of html 1 on page listing bunch of users. scenario may want find element based on user's name know. in case, can find element contained text, user's name. write function like

public webelement getusername(string username) {     return driver.findelement(by.xpath("//div[contains(@class, 'user')][.='" + username + "']")); } 

and call like

system.out.println(getusername("test12")); 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -