css - Locating an element under div -
<div class="form-item"> <label class="form-item-label">mailing account:</label> <div class="form-element"> <div class="form-field-wrap> <input class="form-text x-form-field x-combo-noedit"> </input>
i trying locate element <input class="form-text x-form-field x-combo-noedit">
comes under <label class="form-item-label">mailing account:</label>
.
first element should matched on text "mailing account:" , second element on of these classes "form-text x-form-field x-combo-noedit".
can suggest logic using using xpath
or cssselector
please?
let me see if understand correctly, want find element classes 'form-text' 'x-form-field' , 'x-combo-noedit', if containing div sibling of label text "mailing account"
way using xpath:
webelement firstelement = driver.findelement(by.xpath("//label[contains(text(), 'mailing account:')]")); webelement secondelement = firstelement.findelement(by.xpath("./following-sibling::div[1]//input[@class='form-text x-form-field x-combo-noedit']"));
or wrote if want match of classes "input" part of second xpath this:
//input[contains(@class,'form-text') or contains(@class ,'x-form-field') or contains(@class ,'x-combo-noedit')]
if want combine 1 expression, can use following xpath:
string xpath = "//label[contains(text(), 'mailing account:')]/following-sibling::div[1]//input[contains(@class,'form-text') or contains(@class ,'x-form-field') or contains(@class ,'x-combo-noedit')]"; // , find element driver.findelement(by.xpath(xpath));
Comments
Post a Comment