samedi 9 février 2019

Selenium Python - Unable to click on check box bound to label with values updated in hidden element

I have a form page for requesting access to one or both of Password/RDP to a server using checkboxes. RDP is checked by default. I want to check Password as well. The form has a frame within which there is

  • a label for text "Access Request"
  • a div that has
    • a hidden input that takes value "2" by default *RDP is always checked) but changes to "2,1" if Password is also checked
    • a label with text "Password" bound to an input which is a checkbox
    • a label with text "RDP" bound to an input which is a checkbox

I want to click on the first checkbox for Password.

Here is html source code:

<div class="control-group access-type">
    <label class="control-label" data-bind="text: translate('view_new_requests:access_request_lbl', { defaultValue: 'Access Request:'})">Access Request:</label>
    <div class="controls div-access-type" data-bind="visible: accessTypes().length > 0">
        <input type="hidden" id="hiRequestAccessType" data-bind="value: requestAccessTypeStr" value="2">
        <div class="retinaCS-validation-message" style="display: none; top: 210.812px; left: 183px; opacity: 0;">
            <em></em>
            <div style="display: table">
                <div class="retinaCS-validation-message-text" style="display: table-cell" data-bind="validationMessage: field"></div>
            </div>
        </div> 
        <!-- ko foreach: $root.accessTypes -->
        <label data-bind="css: 'checkbox' + '&nbsp;' + cssClassName()" class="checkbox viewpwd">
            <input name="rbtnAccessType" type="checkbox" data-bind="value: bitValue(), enable: enabled(), checked: $root.requestAccessTypeStr" value="1">
            <!-- ko text: title() -->Password<!-- /ko -->
        </label>
        <br>                                     
        <label data-bind="css: 'checkbox' + '&nbsp;' + cssClassName()" class="checkbox rdpaccess">
            <input name="rbtnAccessType" type="checkbox" data-bind="value: bitValue(), enable: enabled(), checked: $root.requestAccessTypeStr" value="2">
            <!-- ko text: title() -->RDP Session<!-- /ko -->
        </label>
        <br> 
        <!-- /ko -->
    </div>
    <div class="controls read-only-label" data-bind="visible: accessTypes().length == 0" style="display: none;">
        <span class="form-value-label" data-bind="text: translate('view_new_requests:no_accessTypes_lbl', { defaultValue: 'No access request types available. Contact your administrator.'})">No access request types available. Contact your administrator.
        </span>
    </div>                            
</div>

Note:

    wait = ui.WebDriverWait(driver, 10)

where driver is a Chromedriver instance. Also, I have switched to aforementioned frame.

I tried the following:

1.Setting the value of hidden element to '2,1':

passwordcheck_input_element = driver.find_element_by_css_selector("#hiRequestAccessType")
new_value = '2,1'
driver.execute_script("arguments[0].value = arguments[1].toString()", passwordcheck_input_element, new_value)

2.Click on checkbox directly:

chckbox = wait.until(EC.element_to_be_clickable((By.NAME, "rbtnAccessType")))

OR

chckbox = driver.find_element_by_xpath("//label/input[contains(..,'Password')]")

followed by

chckbox.click()

This is what I see:

1.The value changes successfully to '2,1' but the box for password is not checked so nothing really happens. It is only RDP that is chosen at the back end upon clicking through to the next page.

2.Nothing happened. No error but no checkbox action either. I think it didn't find the checkbox element but something else. If I query chckbox.name, it returns error saying WebElement has no attribute "name" where I expected to see "rbtnAccessType".




Aucun commentaire:

Enregistrer un commentaire