how to print the selected dropdown value in selenium?
4608
['Select select = new Select(driver. findElement(By. xpath("//select")));', 'WebElement option = select. getFirstSelectedOption();', 'String defaultItem = option. getText();', 'System. out. println(defaultItem );']
23694
$var = jQuery("#dropdownid option:selected"). val(); alert ($var); Or to get the text of the option, use text() : $var = jQuery("#dropdownid option:selected").
613094
['var selectedText2 = $("#SelectedCountryId:selected"). text();', 'var selectedText2 = $("#SelectedCountryId option:selected"). text();', 'var selectedID = $("#SelectedCountryId"). val();']
155638
How to Display Selected Value From Dropdown List. For Example if I have a dropdown list of years like: <? php $years = array(); for ($i = 1900; $i < 2026; $i++) { $years[] = $i; } echo "<select name='Year'>"; foreach($years as $option){ echo "<option value='{$option}'>{$option}</option>"; } echo "</select>"; ?>
1147488
You can use one single line to select the dropdown option. Avoid any extra line/code to click the dropdown. First you have to locate the web-element uniquely presented as select list on UI, you can use Firebug for that to find list element's id, name, xpath or css path.
259556
['<title>jQuery Get Selected Radio Button Value</title>', '<script>', '$("input[type=\'button\']"). click(function(){', 'var radioValue = $("input[name=\'gender\']:checked"). val();', 'if(radioValue){', 'alert("Your are a - " + radioValue);', '}', '});']
1153382
['Bind the data to the select list in Angular 5/4 using ngFor.', 'To get the selected value from the dropdown list.', 'To set the default value of the dropdown list.', 'Call a custom function on the change event of the dropdownlist.']
197582
['selected=”selected” is required with-in a particular option tag to remain it selected with-in the drop-down list.', '$selected = “”;', "if( $_POST[ 'bookCode' ] == $book_row[ 'bookCode' ] ) {", '$selected = “selected”;', '}']
396882
['Dropdowns in Protractor | Select Class.', 'Create Select class in Protractor Typescript.', 'selectByIndex(index:number)', 'selectByValue(String value)', 'selectByVisibleText.', 'getOptions()', 'isMultiple.', 'Select class in protractor.']
421452
To get an XPATH of an element right-click the Dropdown menu and select 'Inspect element with Firebug'. Then corresponding code would be highlighted in the firebug, right-click on it and select copy XPath. By this method we can copy the XPATH and paste it into the Selenium IDE tool's Target section.
1288475
['$( "#selectOption" ). click(function() {', '$("#myDropdown option:contains(Option 2)"). attr(\'selected\', \'selected\');', '});']
793690
["document. getElementById('submit'). onclick = function() {", "var select = document. getElementById('pets');", 'var selected = [... select. options]', '. filter(option => option. selected)', '. map(option => option. value);', 'alert(selected);']
1115994
['<script>', '$( ". dropdown" ). change(function() {', 'dropdownval = $( ". dropdown" ). val();', '$(". dropdown option[value=\'dropdownval\']"). remove();', '});', '</script>']
308829
['Create a jsp page that contains the <%code fragment%> scriptlet. ... ', 'Use the <c:choose> tag, that works like a Java switch statement in that it lets you choose between a number of alternatives.']
643098
Here is the code snippet where I click on the dropdown: //Choose a Template from Dropdown WebElement dropdownBtn = webDriver. findElement( By.id("select2-id_template_or_inspection-container")); dropdownBtn. click();
1401411
['IWebElement dropDownListBox = driver. findElement(By. ... ', 'using OpenQA. Selenium. ... ', 'element = @driver. ... ', "def select(locator, value, type='css') find(type. ... ", 'element = driver. ... ', 'def multiselect_set_selections(driver, element, labels): element = driver.']
105265
['1st Approach (via Request or FormCollection): You can read it from Request using Request.Form , your dropdown name is ddlVendor so pass ddlVendor key in the formCollection to get its value that is posted by form: string strDDLValue = Request. ... ', '2nd Approach (Via Model): ... ', 'UPDATE:']