I have some stray text next to radio buttons in a radio button group. I tried to obtain it using xpath and watir, but I had no luck with it. Here's some sample HTML for it
<html>
<head></head>
<body>
<input type="radio" name="options" value="No">No <br />
<input type="radio" name="options" value="Yes">Yes <br />
<input type="radio" name="options" value="Maybe">Maybe <br />
</body>
</html>
I can obtain the selected radio button using xpath by
selectedRadio = browser.radio(:xpath,"//input[#checked and #name='options']")
How can I obtain say Yes, No, Maybe if the corresponding radio buttons are selected? I also tried to obtain it using Watir, but the .text method would not work on the Watir::RadioButton object which would be true since the texts are stray texts.
Thanks in advance.
That HTML given is not well-formed XML, so I think the expression will depend on how Waitr parses the input. If it thinks that the text is a child of the input elements, like this:
<input type="radio" name="options" checked="checked" value="No">No </input><br />
<input type="radio" name="options" value="Yes">Yes </input><br />
<input type="radio" name="options" value="Maybe">Maybe </input><br />
Then use this expression:
//input[#checked and #name='options']/text()
If, on the other hand, it automatically closes the input and treats the text as a sibling, like this:
<input type="radio" name="options" checked="checked" value="No"/>No <br />
<input type="radio" name="options" value="Yes"/>Yes <br />
<input type="radio" name="options" value="Maybe"/>Maybe <br />
Then use the following expression:
//input[#checked and #name='options']/following-sibling::text()[1]
My guess is that this second one is the correct one, since you already said that .text did not work.
Ask the developer to make the page more testable by putting the text associated with the radio button inside a label associated with the button via an ID value
<form>
<input type="radio" name="sex" id="male" />
<label for="male">Male</label>
<br />
<input type="radio" name="sex" id="female" />
<label for="female">Female</label>
</form>
Then you can get the ID for the selected button, and find the associated label text fairly easily.
Seriously, it's a likely a lot easier for them to do that than it is for you to have to deal with sloppy page code. It also offers them a lot more formatting options (via CSS) to have that text inside a label container. Win all around.
Related
Hello I'm working with a broken web form, the issues is that the current form would only pop up after loading the PDF in a different window tab.
The form is completely ignored after clicking the PDF url, which is redirected into a new tab, without giving any information. I'm working with a drupal site which is version 8.4. I've researched modules and only found web form modules that support Drupal 7 and below. Is there way to fix this current one? I'm still researching on other options.
here's the link to the site https://adnetcmm.com/resources
<div class="overlay" style="display:none">
<div class="contactForm" style="display:none"><b><span class="close">✖</span> </b>
<div>
<p><b>Please submit form to download Pdf</b></p>
</div>
<b> </b>
<form action="#" method="post"><b><input class="inputc" name="name" placeholder="Name" required="" type="text" value="" /> <input class="inputc" name="email" pattern="[a-z0-9._%+-]+#[a-z0-9.-]+\.[a-z]{2,3}$" placeholder="Email" required="" type="text" value="" /> <input class="inputc" name="phone" pattern="[789][0-9]{9}" placeholder="Phone" required="" type="text" value="" /><textarea class="textarea" name="comment" placeholder="Comments.." required=""></textarea> <input class="contbtn" id="ajaxpdf_submit" name="submit" type="submit" value="Submit" /> </b></form>
<b> </b></div>
</div>
</div>
I have a editor template DisplayConfig. In DisplayConfig
#model string
<input id="#(Model)_DisplayOrder" class="DisplayTypeConfigurator" type="number" />
<input id="#(Model)" class="DisplayTypeConfigurator" type="checkbox" />
I want to call this template in my view and send string so i get different id for every textbox.
In my view
#Html.Editor("Tab_Info_Product", "DisplayConfig")
I do not want to send the value through my model.
I want the result like
<input id="Tab_Info_Product_DisplayOrder" class="DisplayTypeConfigurator" type="number" />
You should use #Html.IdForModel() to construct the ids of your <input> tags.
<input id="#Html.IdForModel()_DisplayOrder" class="DisplayTypeConfigurator" type="number" />
<input id="#Html.IdForModel()" class="DisplayTypeConfigurator" type="checkbox" />
Im trynig to create a simple multiselect box but for some reason its not visible properly.
Here is my code:-
HTML
<input type="text" id="addRow" />
<input type="button" id="btn" value="Add" />
<form id="form1">
<div style="padding:20px">
<select id="chkveg" multiple="multiple"></select>
<br />
<br />
</div>
</form>
https://jsfiddle.net/04Lgnkqs/
After creating the select you should call the plugin on your select. something like this
$('#chkveg').multiselect();
Refer here
Radio Button checked item should be true based on entry.isalbum value. Below is my View code..
#foreach(abc.Models.ddt entry in entrydetails)
{
#if(entry.isAlbum=="Album")
{
<input type="radio" id="c" name="isAlbum" checked="checked" value="Album" />
<label style="margin-right:10px" for="c"><span></span>Album</label>
}
<input type="radio" id="c1" name="isAlbum" value="Movies" />
<label style="margin-right:10px" for="c1"><span></span>Movies</label>
<input type="radio" id="c2" name="isAlbum" value="Single" />
<label style="margin-right:10px" for="c2"><span></span>Single</label>
</div>
}
}
foreach loop contain value stroed in database corresponding to Album, Movies or Single.
radio button checked should be true based on entry.isAlbum vale. How can we do this, please help to us? I have three radiobutton mention in above code. Radio Button checked will be true based on entry.Isalbum vale. Please help me
Try this:
<input type="radio" id="c" name="isAlbum" #if(entry.isAlbum=="Album"){<text>checked="checked"</text>} value="Album" />
<input type="radio" id="c1" name="isAlbum" #if(entry.isAlbum=="Movies"){<text>checked="checked"</text>} value="Movies" />
<input type="radio" id="c2" name="isAlbum" #if(entry.isAlbum=="Single"){<text>checked="checked"</text>} value="Single" />
Say I have a simple cfform that looks like this:
<cfform id="fruitForm" method="post" action="">
<cfinput type="radio" name="fruit" id="fruit_apple" value="Apple" /><label for="fruit_apple">Apple</label><br />
<cfinput type="radio" name="fruit" id="fruit_orange" value="Orange" /><label for="fruit_orange">Orange</label><br />
<cfinput type="radio" name="fruit" id="fruit_pear" value="Pear" /><label for="fruit_pear">Pear</label><br />
<cfinput type="submit" name="submitFruit" id="submitFruit" value="Submit" />
</cfform>
How can I use the built-in cfform validation to ensure that at least one radio button in this group is selected? I've tried adding a validate="required" to each of the radio buttons but it doesn't work. Is there any simple way to "require" one of the buttons to be selected using cfform validation?
Do yourself a favor and don't use cfform for validation. Write your own server and client side validation, but according to the cfinput documentation if you add a required="true" attribute to each radio button ColdFusion will do the client side validation for you.
Note: The user can bypass this validation and still submit a form without checking a radio button. You need to have server side validation as well.
<cfform id="fruitForm" method="post" action="">
<cfinput type="radio" name="fruit" id="fruit_apple" value="Apple" required="true" /><label for="fruit_apple">Apple</label><br />
<cfinput type="radio" name="fruit" id="fruit_orange" value="Orange" required="true" /><label for="fruit_orange">Orange</label><br />
<cfinput type="radio" name="fruit" id="fruit_pear" value="Pear" required="true" /><label for="fruit_pear">Pear</label><br />
<cfinput type="submit" name="submitFruit" id="submitFruit" value="Submit" />
</cfform>
This works for me:
<cfform action="abc.cfm" method="post">
<cfinput type="radio" required="yes" message="pick something" name="x" value="1">radio 1
<cfinput type="radio" required="yes" message="pick something" name="x" value="">radio 2
<input type="submit" />
</cfform>
In fact, you don't even need the message attribute. It will still validate.