I'm writing a small java application to automate report downloading using Selenium and the IE Webdriver. There are twenty fields which can be selected by a user in one area, and then by clicking a button, the field is moved from availabaleFieldsList to selectedFieldsList. An HTML sample is below.
Is it possible to execute some javascript on the page to insert all values in the selectedFieldsList? Similar to JavaScriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementById('id').removeAttribute('attribute')");
<select name="BLANK.availableFieldsListArray" multiple="multiple" size="8" style="width:200;" id="availableFieldsListArray">
<option value="20~L0145~BLANK20~custom" selected="selected">Blank 20</option>
</select>
<select name="BLANK.selectedFieldsList" multiple="multiple" size="8" style="width:200;" id="selectedFieldsList">
<option value="1~L0117~BLANK1~null">Blank 1</option>
<option value="2~L0101~BLANK2~null">Blank 2</option>
<option value="3~L0119~BLANK3~null">Blank 3</option>
</select>
Related
I have currently hit a stumbling block when trying to simply pick an option from a dropdown menu whilst automating a website.
Here is a snippet of the HTML:
<select id="alarm-dropdown" name="alarm-dropdown" data-bind="value: AlarmCode" data-ga-category="CarInsurance_YourVehicle_VehicleDetails_FittedWithAnAlarm" data-ga-action="Selected" data-ga-label="CarInsurance_YourVehicle_VehicleDetails_FittedWithAnAlarm">
<option class="" selected="" disabled="" value="">Please select...</option>
<option class="" id="alarm-dropdown-99991" value="99991">Factory Fitted Thatcham Approved Alarm/Immobiliser</option>
<option class="" id="alarm-dropdown-99992" value="99992">Factory Fitted Thatcham Approved Alarm</option>
<option class="" id="alarm-dropdown-99993" value="99993">Factory Fitted Non-Thatcham Alarm/Immobiliser</option>
<option class="" id="alarm-dropdown-99994" value="99994">Factory Fitted Non-Thatcham Alarm</option>
<option class="" id="alarm-dropdown-#F" value="#F">Factory Fitted</option>
<option class="" id="alarm-dropdown-#N" value="#N">None</option>
</select>
Here is my current code: -
Select select = new Select(driver.findElement(By.id("alarm-dropdown")));
select.selectByValue("Factory Fitted Non-Thatcham Alarm");
I have tried XPATH/ID/CSS
Select select = new Select(driver.findElement(By.id("alarm-dropdown")));
select.selectByValue("99994");
Try with the xpath:
driver.findElement(By.xpath("//select[#id='alarm-dropdown']/option[#value='99994']")).click();
I try to load conditional value to a select tag based on the user's choice on a pervious form tag. it might require java or php. i am not competent in any of those two language.
the logic is explain as the following.
<form>
<input name="complaint" value="copyright" type="radio">copyright <br>
<input name="complaint" value="trademark" type="radio">trademark <br>
<input name="complaint" value="other_concern" type="radio"> other concerns
</form>
if complaint="copyright" then
<select>
<option value="image">image</option>
<option value="product">product</option>
</select>
elseif complaint="trademark" then
<select>
<option value="item">item</option>
<option value="image">image</option>
</select>
elseif complaint="other_concern"
<select>
<option value="explain">explain</option>
</select>
end if
any solution?
Heres a solution in Jquery. Add a class name to the inputs and hide the selct options by default
<input name="complaint" value="copyright" type="radio" class="complaint">
then add unique ID tags to the select options along with a css class i like to use, .addClass and .removeClass are slighty faster and more efficent than .hide() and .show() selectors
Add the css at the bottom of your css sheet
.hidden{position:absolute;width:0;height:0;overflow:hidden;visibility:0;padding:0;margin:0}
<select id="copyright" class="selectOptions hidden">
<option value="image">image</option>
<option value="product">product</option>
</select>
Finally add some JQuery You need to copy the remainder for your other hidden values
$('.complaint').click(function() {
$('.selectOptions').addClass('hidden');
var checkComplaint = $(this).val();
$('#' + checkComplaint).removeClass('hidden');
});
In my web application, I am working on a screen, where I want to display retrieved data onto the screen. In my screen I have one drop down for "direction". I am setting value of this field from servlet. But I am not getting a way to display the selected option by default in the page.
<select name="indv_adr_mail_st_dir" value="${indv_adr_mail_st_dir}">
<option value="EA">East</option>
<option value="NE">North East</option>
<option value="NO">North</option>
<option value="NW">North West</option>
<option value="SE">South East</option>
<option value="SO">South</option>
<option value="SW">South West</option>
<option value="WE">West</option>
</select>
What is the way to achieve this?
The reason this doesnt work is the <select> tags selected option is designated by placing the selected attribute on a specific option, not by setting the value attribute. For instance
<select name="test">
<option value="yes">Yes</option>
<option selected value="no">No</option> <!-- this is the selected option -->
</select>
For your code you could make this happen by using a ternary operator to optionally place the selected attribute on an option
<select name="indv_adr_mail_st_dir">
<option ${indv_adr_mail_st_dir=="EA"?"selected":""} value="EA">East</option>
<option ${indv_adr_mail_st_dir=="NE"?"selected":""} value="NE">North East</option>
<option ${indv_adr_mail_st_dir=="NO"?"selected":""} value="NO">North</option>
<option ${indv_adr_mail_st_dir=="NW"?"selected":""} value="NW">North West</option>
<option ${indv_adr_mail_st_dir=="SE"?"selected":""} value="SE">South East</option>
<option ${indv_adr_mail_st_dir=="SO"?"selected":""} value="SO">South</option>
<option ${indv_adr_mail_st_dir=="SW"?"selected":""} value="SW">South West</option>
<option ${indv_adr_mail_st_dir=="WE"?"selected":""} value="WE">West</option>
</select>
Hello im not able to find following dropdown element. Here is HTML code:
<div class="FormDetails"><br>
<ul class="lsn"><br>
<li><br>
<span id="errfileName"></span><br>
</li><br>
<li style="display: block;"><br>
<div class="LeftSection-Form" style="margin-bottom: 15px;"><br>
<div class="FormLabel"><br>
<Community<br>
<span class="FormDetails_required"> Required</span><br>
</div><br>
<div class="FormValue"><br>
<select id="Fact-Communities-LIVE" class="ToolTipPopup Sel1355" tooltip-title=<p>"Community "</p> onkeydown="return preventBackspace(event);" <br>onchange="dropDownValue(this);" name="Fact.Communities.LIVE" emptyoption="-Please select-"><br>
<option value="TxnyD.PleaseSelect.1.1">-Please select-</option><br>
<option value="TxnyD.Communities.1.1">UVDB</option><br>
<option value="TxnyD.Communities.2.1">THQS</option><br>
<option value="TxnyD.Communities.3.1">Master</option><br>
<option value="TxnyD.Communities.4.1">Connexio</option><br>
<option value="TxnyD.Communities.5.1">SL</option><br>
<option value="TxnyD.Communities.6.1">OG</option><br>
<option value="TxnyD.Communities.7.1">UT</option><br>
<option value="TxnyD.Communities.8.1">TR</option><br>
<option value="TxnyD.Communities.9.1">FGW</option><br>
<option value="TxnyD.Communities.10.1">E.ON TSMS</option><br>
<option value="TxnyD.Communities.11.1">Vattenfall TSMS</option><br>
<option value="TxnyD.Communities.12.1">Delivery1</option><br>
<option value="TxnyD.Communities.13.1">Test community</option><br>
<option value="TxnyD.Communities.14.1">Automotive</option><br>
<option value="TxnyD.Communities.15.1">SHELL SUPPLIER QUALIFICATION SYSTEM</option> <br>
<option value="TxnyD.Communities.17.1">Nestle</option><br>
<option value="TxnyD.Communities.18.1">BuildingConfidence</option><br>
</select><br>
</div><br>
</div><br>
i tried following script to find these element:
//driver.findElement(By.xpath(".//*[#id='Fact-Communities-LIVE']")).click();
//driver.findElement(By.xpath(".//*[#id='Fact-Communities-LIVE']/option[16]/text()='SHELL SUPPLIER QUALIFICATION SYSTEM'")).click();
tried these one as well:
//driver.findElement(By.id("Fact-Communities-LIVE")).sendKeys("SHELL SUPPLIER QUALIFICATION SYSTEM");
//Thread.sleep(1000);
//new Select(driver.findElement(By.id("Fact-Communities-LIVE"))).selectByVisibleText("SHELL SUPPLIER QUALIFICATION SYSTEM");
& these one as well
//WebElement dropDown = driver.findElement(By.xpath(".//*[#id='Fact-Communities-LIVE']"));
//List<WebElement> options = dropDown.findElements(By.xpath(".//*[#id='Fact-Communities-LIVE']/option[16]/text()"));
//driver.findElement(By.xpath(".//*[#id='Fact-Communities-LIVE']/option[16]")).click();
but seem to be something going wrong ..please any one guide me for these.
Try below code
WebElelment dropDown = driver.findElement(By.id("Fact-Communities-LIVE"));
new Select(dropDown).selectByVisibleText("SHELL SUPPLIER QUALIFICATION SYSTEM");
or
new Select(dropDown).selectByValue()("TxnyD.Communities.15.1");
Use the Select class:
Select select = new Select(driver.findElement(By.Id("Fact-Communities-LIVE");
and then use the option you want to select the options, by value, by text, by index etc.
Also check all the tags on the html if all of them are properly open and closed
i am using struts tag with . there are two opt groups with same keys but different values. when i submit my form, keys go to server to save. now on server side i want to check with which optgroup it was associated how can i do it ?
following is html code
<optgroup label="Group1">
<option value="1">opt1</option>
<option value="3">opt2</option>
<option value="4">opt3</option>
</optgroup>
<optgroup label="Group2">
<option value="1">opt4</option>
<option value="3">opt5</option>
<option value="4">opt6</option>
</optgroup>
Use different values, such as:
<option value="grp1_1">opt1</option>
...
<option value="grp2_1">opt1</option>
Then parse out the value on the server after the for is submitted.