Issue
**HTML Code**
<div class="form-group">
<label class="control-label col-md-4 col-sm-4" for="type-select">Category<span style="color:red">*</span></label>
<div class="col-md-8 col-sm-8">
<select defaultattr="4" class="form-control input-style mandatory" data-val="true" data-val-number="The field CategoryID must be a number." id="CategoryID" name="CategoryID"><option value="">--Select--</option>
<option value="1">Architectural Firm</option>
<option value="2">Interior Design Firm</option>
<option value="3">General Contractor</option>
<option selected="selected" value="4">2tec2 Sales Network</option>
<option value="5">Cleaning Company</option>
<option value="6">Commercial end user</option>
<option value="7">Distribution company</option>
<option value="8">Hotel Company</option>
</select>
I Want the xpath to get the selected value(here it is 4th option in above code).
Solution
You want the xpath to get the selected option of a drop down?
Try this xpath: //select[@id='CategoryID']//option[@selected='selected']
You get the text of the selected text using GetText()
String text = driver.findElement(By.xpath(...)).getText();
Answered By - Shn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.