I have a problem with options after re-opening browser - radio-button

I am having difficulty understanding what is going on with Options and radio button settings after closing and re-opening a browser with "continue where I left off" set. Chrome & Edge both behave the same way.
I want EITHER to get javascript to behave according to how the option and radio buttons are displaying OR force the option and radio buttons to display default values (i.e. to match the values that javascript thinks are set).
What I am doing:-
a) I change the radio button to Radio Button 2. I close the browser and re-open it. The radio button indicates Radio Button 1. Javascript also behaves as though Radio Button 1 is checked. All OK.
b) I change the option to Option 2, change the radio Button to Radio Button 2. I close the browser and re-open it. The radio button indicates Radio Button 1. Javascript also behaves as though Radio Button 1 is checked. The option continues to display as Option 2, but javascript indicates that option 1 is selected.
c) I change the radio Button to Radio Button 2, change the option to Option 2. I close the browser and re-open it. The radio button indicates Radio Button 2. Javascript behaves as though Radio Button 1 is checked. The option continues to display as Option 2, but javascript indicates that option 1 is selected.
This is all quite unexpected, and I don't see how to force the option and radio buttons to indicate their selected values. This only ever happens after closing and re-opening the browser.
My code is here
<select id="sel">
<option value=1 selected>Option 1</option>
<option value=2>Option 2</option>
<option value=3>Option 3</option>
</select>
<p>Radio Buttons<br/>
<input type="radio" id="r1" name="rb" value="rb1" checked> Radio Button 1
<input type="radio" id="r2" name="rb" value="rb2"> RadioButton 2
</p>
<span id="debug"></span>
<script>
debug();
function debug(){
var e=document.getElementById("sel");
var rb1val = document.getElementById("r1").checked;
document.getElementById("debug").innerHTML="Option "+e.options[e.selectedIndex].value+" is selected. Radio Button 1 is "+rb1val;
document.getElementById("r1").value;
}
</script>

After much searching, I have found the unlikely answer.
The problem goes away by enclosing the elements in a form with autocomplete="off":-
<form autocomplete="off">
<select id="sel" onchange="debug()">
<option value=1 selected>Option 1</option>
<option value=2>Option 2</option>
<option value=3>Option 3</option>
</select>
<p>Radio Buttons<br/>
<input type="radio" id="r1" name="rb" value="rb1" checked onchange="debug()"> Radio Button 1
<input type="radio" id="r2" name="rb" value="rb2" onchange="debug()"> RadioButton 2
</p>
<span id="debug"></span>
</form>
<script>
debug();
function debug(){
var e=document.getElementById("sel");
var rb1val = document.getElementById("r1").checked;
document.getElementById("debug").innerHTML="Option "+e.options[e.selectedIndex].value+" is selected. Radio Button 1 is "+rb1val;
document.getElementById("r1").value;
}
</script>

Related

How to click on button when <input type =Button> using Selenium

How to click on button when input type is button , I am using below code, click on button is not working?
<p>
<img class="getdata-button" style="float:right;" src="/common/images/btn-get-data.gif" id="get" onclick="document.getElementById('submitMe').click()">
<input type="button" value="Get Results" tabindex="9" id="submitMe" onclick="submitData();" style="display:none" ;="">
</p>
I have tried
driver.find_element_by_css_selector("input[#type='button']")).click()
driver.find_element_by_id("get").click()
driver.find_element_by_id("submitMe").click()
also used xpath for both still nothing
It can be done through JavaScript if that is acceptable for you:
driver.execute_script("document.getElementById('submitMe').click()")
The <img> element fires an onclick event: onclick="document.getElementById('submitMe').click()"; it locates and clicks the <input> element button below in the DOM. The Selenium click interaction can be skipped and call the same JavaScript from the <img> element which should get you the desired result.

vue.js show/hide input field based on radio button selection

I'm trying to customize an out-of-the-box form in Vue.js where inputs are shown/hidden depending on the selection of 2 radio buttons:
<b-form-group label-class="ssrv-form-control">
<div class="ssrv-5">
<b-form-radio v-model="isOperator" name="operatorRad" value="false">Consultant</b-form-radio>
</div>
<div class="ssrv-0">
OR
</div>
<div class="ssrv-1 rad">
<b-form-radio v-model="isOperator" name="operatorRad" value="true">{{ userDetails.operator.description }}</b-form-radio>
</div>
</b-form-group>
I have defined isOperator in the data (am I defining data correctly? I'm trying to modify the out-of-the-box code, not sure what this means):
export default {
name: 'User-Details',
components: {...},
props: {...},
data () {
let data = {
...
isOperator: true,
...
};
and I'm trying to make this show/hide a button and input fields. I'm starting with the button as it seems simpler:
<b-button v-show="isOperator === true" #click="save" :block="true" size="lg" variant="primary" active-class="ssrv-form-button" class="ssrv-form-button">
{{$t("common.form.signUp")}}
</b-button>
My current problem, is the button isn't showing/hiding based on the two radio buttons. If I make isOperator: true in the data, the page loads with the 2nd radio button selected and the button showing. When I click the second radio button, it disappears. But then when I click the original radio button again, the button doesn't show back up. I get the same result when I try to show/hide an input field, I can get it to show initially by setting isOperator to true, but then when I select the other radio button to make it disappear I can't make it appear again. If isOperator is set to false, it just never shows.
I put a isOperator is {{ isOperator }} p element and I can see the value is change true/false as expected, but the buttons/inputs aren't showing back up.
From my very limited understanding of Vue.js, I set the v-model to a variable I want an element to modify, and the value what that variable will be set to when the radio button is selected. Then on a separate element I want to show/hide, I can use v-if/v-show with "myvalue === true/false" to show/hide. Is this an oversimplification and I'm missing steps?
That's because of a mismatch in the type of isOperator property. When you first mount the component the value of isOperator is a boolean (true), and then later on when you click on the radio buttons it becomes a string. You need to adjust the value property in your template as below:
<b-form-group label-class="ssrv-form-control">
<div class="ssrv-5">
<b-form-radio v-model="isOperator" name="operatorRad" :value="false">Consultant</b-form-radio>
</div>
<div class="ssrv-0">
OR
</div>
<div class="ssrv-1 rad">
<b-form-radio v-model="isOperator" name="operatorRad" :value="true">{{ userDetails.operator.description }}</b-form-radio>
</div>
</b-form-group>

Selenium selector for checkbox pseudo-element

<label class="casllic_text" for="Checkbox">
::before
<span>Blob <a class="button link" href="abc.pdf">Terms</a> </span></label>
I want to click on checkbox.
If I use label[for="Checkbox"] as selector, webdriver clicks on Terms link which opens PDF in another tab.
How can I click on checkbox which so far only gets identified if I hover on ::before. (Used inspect element to do that)

Vue v-model not reactive with BS4 radio button group

I'm hoping I'm just missing something simple because I've been looking at this for too long, but I'm stumped.
I have a form with inputs bound to vuejs. I have a group of 2 radio buttons for selecting the "gender", and the binding is working perfectly. If I click on either of the radio buttons, I can see the data change in the vue component inspector.
But I'm trying to change the radio buttons to a Bootstrap 4 button group, and can't seem to get the v-model binding to work. No matter what I try, the gender_id in my vue data is not getting updated when I click either of the buttons in the button group.
The form input values are being fed in through vue component properties, but for simplicity, my data for the radio buttons/button group would look like this:
export default {
data() {
return {
genders: {
1: "Men's",
2: "Women's"
},
gender_id: {
type: Number,
default: null
}
}
}
}
Here is the code I have for the radio button version (which is working properly):
<div class="form-group">
<label>Gender:</label>
<div>
<div class="form-check form-check-inline" v-for="(gender, key) in genders" :key="key">
<input type="radio"
class="form-check-input"
name="gender_id"
:id="'gender_' + key"
:value="key"
v-model.number="gender_id">
<label class="form-check-label" :for="'gender_' + key">
{{ gender }}
</label>
</div>
</div>
</div>
Here is the button group version that is not properly binding to the gender_id data in vue.
<div class="form-group">
<label>Gender:</label>
<div>
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-outline-secondary" v-for="(gender, key) in genders" :key="key">
<input type="radio"
class="btn-group-toggle"
name="gender_id"
:id="'gender_' + key"
:value="key"
autocomplete="off"
v-model.number="gender_id">
{{ gender }}
</label>
</div>
</div>
</div>
I've been using the following Boostrap 4 documentation to try to get this working.
https://getbootstrap.com/docs/4.0/components/buttons/#checkbox-and-radio-buttons
In the documentation for button groups they don't even include the value property of the radio inputs, whereas they do include it in the documentation for form radio buttons.
https://getbootstrap.com/docs/4.0/components/forms/#checkboxes-and-radios
Is this for simplicity or do button groups of radio buttons not even return the value of the checked button?
I see other threads stating that buttons groups are not meant to function as radio buttons, but if that's true for BS4, then why would Bootstrap have button groups with radio buttons as they do in their documentation referenced above? If you can't retrieve the checked state, then why not just use a <button> instead of <label><input type=radio></label>?
Any ideas as to what I'm doing wrong and/or not understanding correctly?
Thanks so much!
Thanks so much to #ebbishop for his helpful insights.
The issue was related to vue and bootstrap both trying to apply javascript to the buttons in the button group.
To get around this issue, it was as simple as removing data-toggle="buttons" from the button group. By removing the data-toggle attribute, the bootstrap js is not applied and vue can manage the button group.
Nothing is actually wrong your use of v-model here.
However: you must add the class "active" to the <label> that wraps each radio-button <input>.
See this fiddle for a working example.
Is that what you're after?

Selecting value from the Dropdown using selenium web-driver

I have a small doubt over here on selecting one of the value from the drop down using selenium . When i generated a code using selenium-IDE it gave me a set of codes for selecting from the drop-down .
Code is as follows-->
driver.findElement(By.cssSelector("input.search")).click();
driver.findElement(By.xpath("//table[#id='project-add-table']/tbody/tr[4]/td[3]/div/div[2]/div[3]")).click();
new Select(driver.findElement(By.cssSelector("select"))).selectByVisibleText("Test");
So can anybody tell what is the use of that second line of code ?After clicking to the dropdown why cant we directly select the required element?
HTML -->
<td class="environmentTd" required="">
<div class="ui fluid search dropdown env selection">
<select>
<option value="SB">Sandbox</option>
<option value="DEV">Development</option>
<option value="QA">Test</option>
<option value="PROD">Production</option>
<option value="PP">Pre Production</option>
<option value="UAT">UAT</option>
<option value="DR">DR</option>
</select>
<i class="dropdown icon"></i><input class="search" autocomplete="off" tabindex="0">
<div class="text">Sandbox</div>
<div class="menu transition hidden" tabindex="-1">
<div class="item active selected" data-value="SB">Sandbox</div>
<div class="item" data-value="DEV">Development</div>
<div class="item" data-value="QA">Test</div>
<div class="item" data-value="PROD">Production</div>
<div class="item" data-value="PP">Pre Production</div>
<div class="item" data-value="UAT">UAT</div>
<div class="item" data-value="DR">DR</div>
</div>
</div>
</td>
If your select tag is visible in DOM without you clicking the dropdown, just use the third line
Select select = new Select(driver.findElement(By.cssSelector("select")));
select.selectByValue("QA");
Otherwise, click on the dropdown which will probably generate the DIV with class
class="menu transition hidden"
and then you can use the select line.
U don't really need to click on dropdown. U need to find dropdown as WebElement, convert it to SelectElement and use it's class method to select option.
I assume, that in provided code you click on dropdown, then click on opened fields with options. But I think it's a lot of unnecessary actions. Unless you have any scripts, triggered by that clicks, which must be tested.
From your description it sounds like the SELECT element isn't visible until the 2nd click happens. It's also possible that the 2nd click creates the SELECT element via Javascript. You could investigate this by using the Chrome devtools and search for the SELECT element before the 2nd click happens. See if it exists or maybe exists but is not visible. Then click on the 2nd element and see how the HTML changes. Without access to the site, that's about as good an explanation as we can provide. It's not something I would worry about. It's just the way the site is designed.