Hope some expert in Robot Framework and Selenium or Selenium2Library could help me figure out how to select this radio button. I've tried many attempts and also search for the solution. The unique thing about this radio button is that it has a javascript in it. Also I'm using IE11 to automate this test.
This is the HTML Codes:
<td>Is turnover figure available?</td>
<td valign="baseline">
<input type="radio" name="turnOverAvailableInd1" value="Y" onclick="javascript:turnOverAvailableToggle(this);" id="turnOverAvailableInd1Yes">YES
<input type="radio" name="turnOverAvailableInd1" value="N" onclick="javascript:turnOverAvailableToggle(this);" id="turnOverAvailableInd1No">NO
</td>
My attempts that pass but does not select on the radio buttons(FAILS) are :
# Click Element xpath=(//input[#name, 'turnOverAvailableInd1'])[2]
# Click Element xpath=//*[contains(#id, 'turnOverAvailableInd1No')]
# Select Radio Button turnOverAvailableInd1 turnOverAvailableInd1No
# Radio Button Should Be Set To turnOverAvailableInd1 No
# Focus xpath=(//input[#name="turnOverAvailableInd1"])
# Press Key xpath=(//input[#id="turnOverAvailableInd1No"]) \\13
#Execute Javascript javascript:turnOverAvailableToggle(this);
Thank you in advance.
I think
Click Element turnOverAvailableInd1No
should work, i've had a similar situation.
You don't have to always use xpaths, the id or the name can be also used as locators.
Radio Button Should Be Set To checks that your radio button is selected (out of a group of radio buttons, only if the group is defined).
In the SeleniumLibrary Documentation for the keyword Select Radio Button
arguments: group_name, value
Sets radio button group group_name to value.
The radio button to be selected is located by two arguments:
group_name is the name of the radio button group.
value is the id or value attribute of the actual radio button.
The Group Name refers to common name that the Radio elements have. The Value refers to the value attribute.
So that would make the right approach:
Select Radio Button turnOverAvailableInd1 N
Related
I am making a fillable pdf for a questionnaire in pdf. I have to use radio buttons in the questionnaire. I used the below code snippet to get the value of the radio button group, but it gives me either a null exception or return blank.
I tried a simple code in a blank pdf with just one group of radio buttons with two options and a button.
The code is shown below, where "Group1" refers to the radiobutton group:
var choiceVAL = this.getField("Group1").value; app.alert(choiceVAL);
On clicking the button, the code keeps giving me an exception. I checked all the forums, and this is the code snippet that is used everywhere. I have set the export value to "Y" and "N" respectively.
Can anyone help me with this??
I have a gallery and a radio button.
In the gallery where the user has to answer questions.
Each question can be a radio button with multiple choice answers, for example one could be a yes no response another could be a yes no unknown choice.
These choices are determined from the list field called answerchoice .
In the answerchoice field it might be populated with
yes\no or yes\no\unknown or 1\2\3\4.
Therefore in the items of the radio button I need to pass the values of the answerchoice field
Thank you
If the separator for the options is the \ character, then you can use the Split function to convert that into a collection that you can set to the Items property of the radio button control:
Split(ThisItem.Value, "\")
My page is having multiple Radio buttons and I have selected one of them. Now I need to double check whether its actually got selected and if its True I would like to drive my flow accordingly. Here is how I tried using the Robot Framework
Click Element //*[text()=' Small' ] //*[#name='size']
Radio Button Should Be Set To xpath=(//*[text()=' Small' ] //*[#name='size']) true
I am not sure about the things I specified in the second line. Is this correct
This should do it:
Radio Button Should Be Set To size true
The argument to provide to Radio Button Should Be Set To is not an xpath or other locator, but the group's name.
What the framework does with the argument is to substitute it in this xpath:
xpath://input[#type='radio' and #name='%s']
, get all matching elements, iterate thorough them to find the selected one and assert - case sensitively! - its value is the same as your second argument.
And now you see why your call failed - having provided a full xpath, after the substitution it ended up as invalid/not matched expression and the keyword failed.
I am using the Robot Framework and Selenium2Library
The button has a text of "Save" and there is nothing more unique in it's xpath, so I'm trying to write an xpath based on element's text.
How to write an xpath based on element's text with that piece of html:
<button class="slds-button slds-button--brand cuf-publisherShareButton NARROW uiButton" type="button" data-aura-rendered-by="1571:2954;a" data-aura-class="uiButton">
<span class=" label bBody truncate" dir="ltr" data-aura-rendered-by="1574:2954;a">Save</span>
</button>
(this is in the middle of the document).
EDIT:
It appears that there are few elements with the same text on the next tab (which was invisible at the moment).
How should I write the xpath for the second element with this text? I mean with index=1.
Click Button //button[.//text() = 'Save']
Is the "Robot Framework" way of finding a button with the text "Save" and clicking it.
Fixed from the help of #Tomalak
<3
Try searching for a button which contains a span with your required text
WebElement saveButton = driver.findElement(By.xpath(".//button/span[text()='Save']")
Use following xpath to find a button which have text as save -
//button[contains(.,'Save')]
Use following keyword, which will first verify whether element is present or not and then it will click on element located by locator
Element should become visible xpath=//button/span[text()='Save']
Click Button xpath=//button/span[text()='Save']
There is another built in keyword
Click Element xpath=//button/span[text()='Save']
Try using below xpath:
xpath=//span[contains(text(),'Save')]
Try this -
//span[text()='Save']/ancestor-or-self::button
I have a field that has a "+" Add button in case you want to add more lines. I want to add 2-3 lines with it, then to click on the "+" button from a newly created line to create 2-3 more. The problem is that all buttons are declared the same:
<button class="ng-scope" ng-if="formData.order_request_status == STATUSES['OPEN']" ng-click="addImportMaterial()" style="margin-left: 3px;" type="button">+</button>
I have written the following xpath:
//button[#ng-click='addImportMaterial()']
but this selects all plus buttons and I want only the third one to be pressed. Any ideas? Thanks!
You should try using xpath with index then as below :-
I want only the third one to be pressed
(//button[#ng-click='addImportMaterial()'])[3]
So, (Assuming your using java) use above xpath to locate third button and click as :-
driver.findElement(By.xpath("(//button[#ng-click='addImportMaterial()'])[3]")).click()
Since you will be getting a List of buttons, to press the third one you just have to do buttons.get(2).click();