I'm new to Selenium and want to select a RadioButton inside a group of labels, see Screenshot. The problem is, that all <input> elements have the same name! So I have to select them by the value (or by the label text?)...
I'm using the Java API for Selenium.
** As HTML **
<table width="100%" border="1">
...
<label>
<input type="radio" name="AktarmaSekli" value="SP" checked class="radio" onclick="_doClick('$Refresh', this, '_self', '#_RefreshKW_AktarmaSekli')">Sipariş Planı</label><br>
<label>
<input type="radio" name="AktarmaSekli" value="DF" class="radio" onclick="_doClick('$Refresh', this, '_self', '#_RefreshKW_AktarmaSekli')">DAG Fatura Bilgileri</label><br>
<label>
<input type="radio" name="AktarmaSekli" value="ATR" class="radio" onclick="_doClick('$Refresh', this, '_self', '#_RefreshKW_AktarmaSekli')">ATR Bilgileri</label><br>
<label>
<input type="radio" name="AktarmaSekli" value="AITM" class="radio" onclick="_doClick('$Refresh', this, '_self', '#_RefreshKW_AktarmaSekli')">AİTM Bilgileri</label><br>
<label>
<input type="radio" name="AktarmaSekli" value="COC" class="radio" onclick="_doClick('$Refresh', this, '_self', '#_RefreshKW_AktarmaSekli')">CoC Bilgileri</label><br>
<label>
<input type="radio" name="AktarmaSekli" value="Bakim" class="radio" onclick="_doClick('$Refresh', this, '_self', '#_RefreshKW_AktarmaSekli')">Bakım Faturaları</label><br>
<label>
<input type="radio" name="AktarmaSekli" value="AF" class="radio" onclick="_doClick('$Refresh', this, '_self', '#_RefreshKW_AktarmaSekli')">Araç Bilgileri</label></td></tr>
</table>
Good to know you have solution.. below one may also helps..
If you are trying to click on specific button, if it has value say 'ATR' you can build xpath (or css selector) simply //input[#value='ATR'] or //input[contains(text(),'ATR Bilgileri')]
off-course other ways also there to find required element..
Thanks,
Murali
I got it to work with the following code!!!
private void selectRadioButtonByValue(WebDriver driver, String radioGroupName, String valueToFind) {
List<WebElement> radioGroup = driver.findElements(By.name(radioGroupName));
for (int i = 0; i < radioGroup.size(); i++) {
if(radioGroup.get(i).getAttribute("value").equals(valueToFind)) {
radioGroup.get(i).click();
return;
}
}
throw new org.openqa.selenium.NotFoundException("Element wasn't found by value!");
}
In Page Object Pattern it will be:
#FindBy(xpath = "//*[contains(text(),'ATR Bilgileri')]")
WebElement radioATR;
Related
Web page have element with structure like:
<label>
<input type="checkbox" name="storage_locations" value="3" style="vertical-align: middle;">
<span style="padding-left: 6px;">example.domain.com: [Text] Text_1 (Sometext)</span>
</label>
<label>
<input type="checkbox" name="storage_locations" value="3" style="vertical-align: middle;">
<span style="padding-left: 6px;">example.domain.com: [Text] Text_2 (Sometext)</span>
</label>
<label>
<input type="checkbox" name="storage_locations" value="3" style="vertical-align: middle;">
<span style="padding-left: 6px;">example.domain.com: [Text] Text_3 (Sometext)</span>
</label>
How i can select input-element located in label with span-element which contains 'Text 2' (for example)?
I know that i could find span-element using this code:
example = driver.find_element(By.XPATH,'//*/label/span[contains(text(),"Text_2")')
But i'm new in selenium-python and haven't ideas what to do next
There are always multiple ways to do things.
You can try with css selector:
driver.find_element(By.CSS_SELECTOR, "body > label:nth-child(2) > input[type=checkbox]")
Or with name:
driver.find_element(By.NAME, "storage_locations")
You can always do it with xpath too. Hope this helps.
I solved my question with help of two array.
text_list = 'text1,text2,text3,ect'
text_array = text_list.split(',')
input_checkbox_array = driver.find_elements(By.XPATH,'//*[xpath_to_find_checboxes')
span_text_array = driver.find_elements(By.XPATH,'//*[xpath_to_find_inputs')
for datastore in datastores_array:
i = 0
while datastore not in span_text_array[i].text:
i += 1
actions.move_to_element(input_checkbox_array[i])
actions.click(input_checkbox_array[i])
actions.perform()
I need to print value of a disabled text box. The below given is the source code
<div class="col-6 col-md-2 form-group mb-2" xpath="1">
<input name="SMDetailsViewModel.SoRSummaryRowID" class="form-control rum-disabled" id="SRowID" type="hidden" value="3908" tabindex="-1">
<input name="SMDetailsViewModel.ID" **value**="20445" class="form-control rum-disabled " id="SID" type="text" tabindex="-1">
</div>
The 'value' needs to get printed and it is dynamic value.
I have tried with CSS, Xpath like below
WebElement SoR=driver.findElement(By.cssSelector("#SID")); With xpath as well
String SoRID=SoR.getText();
System.out.println("Here SOR ID" +SoRID);
tried with GetAttribute as well
Working with below
WebElement SoR=driver.findElement(By.cssSelector("#SID"));
String SoRID=SoR.getAttribute("value");
//String SoRID=SoR.getText();
System.out.println("Here SOR ID" +SoRID);
How to select C++ value if any radio button not selected
<form name="testform" action="" method="POST">
<div align="center">
<br>
<input type="checkbox" name="option-1" value="Java">Java
<input type="checkbox" name="option-2" value="C++">C++
<input type="checkbox" name="option-3" value="Python">Python
</br>
</div>
We can induce a simple check on the WebElement to check if it is selected or not and if not selected click on it to select as follows:
WebElement element= driver.findElement(By.xpath("//input[#name='option-2']"));
if(!element.isSelected())
{
element.click();
}
You can use this :-
webElement element= driver.findElement(By.xpath("//input[#name='option-2']"));
element.getAttribute("value"))
or
element.getText();
When i pass //input[#type='radio'] in the xpath, i'm able to select all the radio buttons in the list but i am not able to select a particular radio button by it's name.
Name of the radio button is the fourth term in quotes inside the render_selected_term list.
<input type="radio" onclick="Element.show('indicator_radio_term_190');render_selected_term('190','1','275464','AQCB Number')" value="190" name="radio_190"/>
<input type="radio" onclick="Element.show('indicator_radio_term_179');render_selected_term('179','1','275464','AQCB Number (iLink)')" value="179" name="radio_179"/>
<input type="radio" onclick="Element.show('indicator_radio_term_19');render_selected_term('19','1','275464','Acceptance')" value="19" name="radio_19"/>
<input type="radio" onclick="Element.show('indicator_radio_term_148');render_selected_term('148','1','275464','Account (iLink)')" value="148" name="radio_148"/>
<input type="radio" onclick="Element.show('indicator_radio_term_206');render_selected_term('206','1','275464','Additional Non-standard Terms')" value="206" name="radio_206"/>
<input type="radio" onclick="Element.show('indicator_radio_term_220');render_selected_term('220','1','275464','Assigned Contract Manager (iLink)')" value="220" name="radio_220"/>
<input type="radio" onclick="Element.show('indicator_radio_term_12');render_selected_term('12','1','275464','Assignment')" value="12" name="radio_12"/>
<input type="radio" onclick="Element.show('indicator_radio_term_188');render_selected_term('188','1','275464','Authorized Purchasing Entity(ies)')" value="188" name="radio_188"/>
<input type="radio" onclick="Element.show('indicator_radio_term_226');render_selected_term('226','1','275464','Award (iLink)')" value="226" name="radio_226"/>
<input type="radio" onclick="Element.show('indicator_radio_term_196');render_selected_term('196','1','275464','Award Amount')" value="196" name="radio_196"/>
I would suggest you to use css selector in this case and attribute search. Be very careful when you use the following selector. The match you are looking for has to be unique.
Note: I am not sure which match you are looking for. So, I am showing you an example.
[onclick*='148']
Should match <input type="radio" name="radio_148" value="148" onclick="Element.show('indicator_radio_term_148');render_selected_term('148','1','275464','Account (iLink)')"/>
Try this:
<div id="something">
<input type="radio" onclick="Element.show('indicator_radio_term_190');render_selected_term('190','1','275464','AQCB Number')" value="190" name="radio_190"/>
<input type="radio" onclick="Element.show('indicator_radio_term_179');render_selected_term('179','1','275464','AQCB Number (iLink)')" value="179" name="radio_179"/>
IList<IWebElement> inputs = browser.FindElements(By.XPath("//div[#id='something']/input)");
foreach(var element in inputs)
{
if(element.getAttribute("name").Equals("radio_12"))
element.Click();
}
I need to render a MultiCheckbox like below:
Wanted:
<label>
<input type="checkbox" name="privacy[read_only]" value="1" /> Just for read only
</label>
<label>
<input type="checkbox" name="privacy[is_pulic]" value="1" /> Is public
</label>
How can I do that? I just can do with:
Unwanted:
<label>
<input type="checkbox" name="privacy[]" value="read_only" /> Just for read only
</label>
<label>
<input type="checkbox" name="privacy[]" value="is_pulic" /> Is public
</label>
Thanks so much for any your ideas.
If there was nothing else in your form, or you didn't mind each form element having the same format, you could use setElementsBelongTo($array) which is a method on a Zend_Form.
You might also then have to use individual checkboxes to acheive the desired markup, so this may or may not work in your scenario.