I need to be able to select one item from a dropdown list (the items in the list are checkboxes) but I cannot seem to get the code correct. The web page is an internal site so I cannot provide the actual link, however here are they Elements:
To activate the dropdown list:
<input name="m_sqlRsWebPart$ctl00$ctl19$ctl06$ctl09$txtValue" type="text" size="28" readonly="readonly" id="m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09_txtValue" title="Support Group report parameter" class="null">
The item from the list I need is:
<input id="m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09_divDropDown_ctl184" type="checkbox" name="m_sqlRsWebPart$ctl00$ctl19$ctl06$ctl09$divDropDown$ctl184" onclick="$get('m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09').control.OnValidValueClick(this, 'm_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09_divDropDown_ctl00');">
What I have tried so far is(snippet):
driver.find_element_by_name("m_sqlRsWebPart$ctl00$ctl19$ctl06$ctl09$txtValue").click()
driver.find_element_by_id("m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09_divDropDown_ctl184").click()
Does not do anything.
Full HTML for the list box:
<div onactivate="event.cancelBubble=true;" style="white-space:nowrap;">
<input name="m_sqlRsWebPart$ctl00$ctl19$ctl06$ctl09$txtValue" type="text" size="28" readonly="readonly" id="m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09_txtValue" title="Support Group report parameter" class="null"><input src="/sites/pa/reports/Reserved.ReportViewerWebPart.axd?OpType=Resource&Version=11.0.5058.0&Name=Microsoft.Reporting.WebForms.Icons.MultiValueSelect.gif" name="m_sqlRsWebPart$ctl00$ctl19$ctl06$ctl09$ddDropDownButton" type="image" id="m_sqlRsWebPart_ctl00_ctl19_ctl06_ctl09_ddDropDownButton" alt="Select a value" title="Select a value" style="vertical-align:top;cursor:pointer;">
</div>
Related
I have the below List in Python.
list_val = ['APPROVED','UN-APPROVED','DEACTIVATE']
and need to pass this list values into a Check box with Jinja Template.
Can someone help on this with HTML code embedded with Jinja template ?
Expected Output:-
HTML Need to converted with JINJA Template.
<input type="checkbox" id="val1" name="val1" value="app">
<label for="val1"> APPROVED</label><br>
<input type="checkbox" id="val2" name="val2" value="unapp">
<label for="val2"> UN-APPROVED</label><br>
<input type="checkbox" id="val3" name="val3" value="deac">
<label for="val3"> DEACTIVATE</label>
Try this code
This code will have input tags with values like approved, un-approved, deacitvate instead of app, unapp, deac. Is that okay for you?
And also its better to put the input tag inside the label tag, because when you click the word beside the checkbox, it'll toggle the checkbox (and thats why labels are mostly used for)
As W3schools says:
Proper use of labels with the elements above will benefit:
Screen reader users (will read out loud the label, when the user is focused on the element)
Users who have difficulty clicking on very small regions (such as checkboxes) - because when a user clicks the text within the <label> element, it toggles the input (this increases the hit area).
Tip: The for attribute of <label> must be equal to the id attribute of the related element to bind them together. A label can also be bound to an element by placing the element inside the <label> element.
{% for i in range(list_val_len) %}
<label for="val{{ i+1 }}" name="val{{ i+1 }}">
<input type="checkbox" id="val{{ i+1 }}" name="val{{ i+1 }}" value="{{ list_val[i].lower() }}">
{{ list_val[i] }}
</label><br>
{% endfor %}
And also pass the list_val list and its length in seperate keyword arguments on the render_template function like
list_val = ['APPROVED','UN-APPROVED','DEACTIVATE']
#app.route('whatever_route_in_here')
def whatever_name_your_function_has():
...
...
render_template('html_file_name.html', list_val=list_val, list_val_len=len(list_val))
Tell me if its not working...
Here is my code :
${verifications} Create List
Set Test Variable ${verifications}
Input text ${societes_input_nom} ${nom_etablissement} ${TEST_NAME}
Append To List ${verifications} ${nom_etablissement} ${TEST_NAME}
Input text ${societes_input_contact_email_casino} ${email}
Append To List ${verifications} ${email}
Input text ${societes_input_contact_adresse} ${adresse}
Append To List ${verifications} ${adresse}
Input text ${societes_input_site_web} ${url_siteweb}
Append To List ${verifications} ${url_siteweb}
FOR ${item} IN #{verifications}
Page Should Contain ${item}
END
Here the HTML for the input :
<div class="form-group">
<label for="title"><h4>Nom de l'établissement
</h4></label>
<br>
<div class="input-group">
<div class="input-group-addon" >
<i class="fa fa-building">
</i>
</div>
<input type="text" style="display: none;" id="initialvalue_prop_1" name="initialvalue_prop_1" maxlength="1000" value="TNR Activite Casino"
/>
<input type="text" id="prop_1" name="prop_1" maxlength="1000" value="TNR Activite Casino"
/>
But, the "page should Contain" do not find my ${nom_etablissement} ${TEST_NAME}
But when i'm looking the page, thoses words are in the page (and the DOM)
The error :
Page should have contained text 'TNR Activite Casino' but did not.
I don't know how to fix that, I tried many thing but nothing work...
Can you help me pls ?
Page Should Contain check for actual text and not the values of the attribute. To get value of attribute you should use -
${Value}= Get Element Attribute xpath://input[#id='initialvalue_prop_1'] value
If you want to assert value inside the textfield then use the keyword -
Textfield Value Should Be ${textfield_locator} ${value_to_be_asserted}
For more details Get Element Attribute
I am trying to find a specific button when there are multiple buttons with the same name. So I have to find the element with the correct 'id' and then click the button nested within. I've been able to do this using the logical xpath but they change the path when new items are added to the page.
Right now, I'm just using:
driver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div[1]/div/div[4]/button').click();
<input type="hidden" name="data[brand_id]" class="brand-id" value="33" id="brand_id">
<div class="input number">
<label for="num-barrels=33">Number of barrels:</label>
<input name="data[num_barrels]" class="number-of-barrels" min="1" id="num-barrels=33" type="number" value="1">
</div>
<button class="add-brand-to-order btn btn-primary btn-block" type="submit">Add to Order</button>
</div>
You can use driver.find_element_by_id().click()
Here is the full documentation for this. Selenium
I want to find the following element:
<input type="text" value="" action-data="text=邮箱/会员帐号/手机号" action-type="text_copy" class="W_input " name="username" ...
And here is the html tags section, there are multiple input with the same name and class properties. So I want to find it using the normal_form div property.
This code does not work:
browser.find_element_by_css_selector('input[action-type="text_copy"]')
I think the field action-type is not a standard field.
What can I do?.
Thanks.
<div class="W_login_form" node-type="normal_form">
<div class="info_list" node-type="username_box">
<div class="inp username ">
<input type="text" value="" action-data="text=邮箱/会员帐号/手机号" action-type="text_copy" class="W_input " name="username" node-type="username" tabindex="1" maxlength="128" autocomplete="off">
</div>
</div>
I am trying, and this way I can find the element.
browser.find_element_by_xpath("//div[#class='W_login_form']/div/div/input")
It finds the div with class W_login_form first, and looks for div and div step in, and last gets the input.
Do you have any good idea about it?
Try this:
browser.find_element_by_xpath("//div[#class='info_list']//input")
I'm using Bootstrap with Flask Python.
request.form.get("name")
#name is the name of the form element(checkbox)
<label class="btn btn-danger pzt active">
<input type="checkbox" name="name" value="1" data-id="0"> Check
</label>
When checkbox is checked, parent label has class "active", I want to get if checked box is checked. Is there any way or methods?
you can try the following:
HTML:
<div class="checkbox">
<label>
<input type="checkbox" name="check" value="edit"> New entry
</label>
</div>
In flask:
value = request.form.getlist('check')
This will give you the value of the the checkbox. Here value will be a list.
value = [u'edit']
You can also get value of multiple checkboxes with same name attribute.
I'm not familiar with Flask, but I do know how HTTP works.
If you want to know if its checked on the server side, just check if that form field exists, if request.form.get("name") gives you NULL or exception, then the checkbox should be unchecked.
If you want to know it on the client side with javascript, you can use jQuery (as jQuery is a base component of Bootstrap) as $('xxxx').is(':checked') (replace xxxx with a valid selector).