I am trying to get a value from a dropdown. I have a class that uploads a video which I then want to publish. I need to change the status in order to do that. I saw another person asking a similar question but none of the suggestions seem to work. I am providing the html, call to the method in the class and the method. Any help is greatly appreciated.
Here is what the select looks like on the web page:
<select id="group_media_953_status" class="status" name="group_media_attributes[953][status]" style="display: none;">
<option value="published" selected="selected">Published</option>
<option value="scheduled">Scheduled</option>
<option value="unpublished">Not Published</option>
</select>
Here is my call to a method:
dropdown("group_media_953_status", "Published");
Here is the method:
public void dropdown(String name, String sel) {
try {
WebElement select = driver.findElement(By.id(name));
List<WebElement> options = select.findElements(By.tagName("option"));
for (WebElement option : options) {
System.out.println(option.getText());
// if(sel.equals(option.getText()))
// option.click();
}
} catch (NoSuchElementException ex) {
System.err.println("Element in dropdown menu was not found");
driver.quit();
System.exit(0);
}
}
Here is the full html. I did not code the html so I will not be able to change it:
<td class="group-status">
<div class="field status">
<select id="group_media_9870_status" class="status" name="group_media_attributes[9870][status]" style="display: none;">
<option value="published" selected="selected">Published</option>
<option value="scheduled">Scheduled</option>
<option value="unpublished">Not Published</option>
</select>
<div id="group_media_9870_status_chosen" class="chosen-container chosen-container-single chosen-container-single-nosearch" style="width: 0px;" title="">
<a class="chosen-single published">
<span>Published</span>
<div>
<b></b>
</div>
</a>
<div class="chosen-drop">
<div class="chosen-search">
<ul class="chosen-results">
</div>
I also tried the xpath and that did not find the select element either. /html/body/div[1]/section/div/div/form[2]/table/tbody/tr[1]/td[3]/div[1]/select and that still did not find the "select" element.