Jump to content

Selecting value in multi-selection check box


jasontj
 Share

Go to solution Solved by Danp2,

Recommended Posts

Hello.  I am attempting to select a value in a Chrome browser from a check box that allows multiple selections, and also allows searching for values.  This is a list of states, and also different regions in the states.  However, I only want to select the top level state name.  I am currently doing this with XPATH.  First I select the field to drop down the list based on XPATH, and then I select the actual value based on XPATH.  This does not work consistently.   I am certain I've got the XPATHs correct, but sometimes I get this error:

 

_WD_FindElement ==> Success [0] : Parameters:   Strategy=xpath   Selector=/html/body/div[22]/div[2]/ul/li[100]/div/div[2]   StartNodeID=Default   Multiple=Default   ShadowRoot=Default
__WD_Post ==> Element interaction issue [14] : HTTP status = 400

 

My question is, is there a way to select this value based on the text name in the list?

Inserted is the HTML and also my code that I am currently using:

<label id="frmSearch:j_idt248" class="ui-outputlabel ui-widget psc-field-label" for="frmSearch:scmRegion">Region</label></div>
<div class="ui-panelgrid-cell ui-grid-col-11 pcl-form-grid-col"><div id="frmSearch:pnlRegion" class="psc-max-width-380" style="width: 100%;">

<div id="frmSearch:scmRegion" class="ui-selectcheckboxmenu-multiple ui-selectcheckboxmenu ui-widget ui-state-default ui-corner-all pcl-selectonemenu" style="width: 280px;" role="combobox" aria-haspopup="listbox" aria-expanded="false">

<div class="ui-helper-hidden-accessible"><input id="frmSearch:scmRegion_focus" name="frmSearch:scmRegion_focus" type="text" readonly="readonly" role="combobox" aria-hidden="true" /></div>

<div class="ui-helper-hidden"><input id="frmSearch:scmRegion:0" name="frmSearch:scmRegion" type="checkbox" value="01" data-escaped="true" />
<label for="frmSearch:scmRegion:11">Alabama</label><input id="frmSearch:scmRegion:12" name="frmSearch:scmRegion" type="checkbox" value="alm" data-escaped="true" />

<label for="frmSearch:scmRegion:12">Alabama Middle</label><input id="frmSearch:scmRegion:13" name="frmSearch:scmRegion" type="checkbox" value="aln" data-escaped="true" />

<label for="frmSearch:scmRegion:13">Alabama Northern</label><input id="frmSearch:scmRegion:14" name="frmSearch:scmRegion" type="checkbox" value="als" data-escaped="true" />



    $FedNum = "22"  ; this value is read from a file because the website changes often.. but I won't need this if I can select by name instead

; next 2 lines will drop down the section list
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[10]/div/div[3]/form[1]/div[1]/fieldset[2]/div/div/div/div[8]/div[2]/div/div[1]/ul")
    _WD_ElementAction($sSession, $sElement, 'click')        
    

    if $SearchArea = "* FED * - AL (Middle)" Then
        $areaSelected = "12"
    endif
    ; this continues for all 50 states and other areas like PR and Guam.

    $areaSelectedPath = "/html/body/div[" & $FedNum & "]/div[2]/ul/li[" & $areaSelected & "]/div/div[2]"
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $areaSelectedPath)
    _WD_ElementAction($sSession, $sElement, 'click')

; next 2 lines will close the selection list
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[10]/div/div[3]/form[1]/div[1]/fieldset[2]/div/div/div/div[8]/div[2]/div/div[1]/ul")
    _WD_ElementAction($sSession, $sElement, 'click')

 

 

 

 

image.png.500db99c5faacc21602a7b7b8c11a35f.png

 

Thanks in advance for any guidance on this issue.

Jason

 

image.png

Link to comment
Share on other sites

You are attempting to automate an advanced control, which appears to be part of the PrimeFaces framework. I haven't delved into it, but they may have APIs that you could use to perform the selection. Otherwise, you could use jQuery selectors.

Hint: it appears to me that you are not clicking on the correct element because the click event is attached to the label element, not the li element

Link to comment
Share on other sites

Thanks @Danp2  The element that I get the XPATH from is this:

 

<div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default"><span class="ui-chkbox-icon ui-icon ui-icon-blank"></span></div>

There is also this element, which I have not attempted anything with:

<li class="ui-selectcheckboxmenu-item ui-selectcheckboxmenu-list-item ui-corner-all ui-selectcheckboxmenu-unchecked" data-item-value="al">

<div class="ui-chkbox ui-widget"><div class="ui-helper-hidden-accessible"><input type="checkbox" id="640b4fba-4758-4780-abd8-292f7be74512"></div><div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default"><span class="ui-chkbox-icon ui-icon ui-icon-blank"></span></div></div><label for="640b4fba-4758-4780-abd8-292f7be74512">Alabama</label></li>

 

Would either of these help me to select a value by the state name or abbreviation?  This one is "AL" for "Alabama". 

I haven't used jQuery selectors before, but I will research those.

 

Link to comment
Share on other sites

@Danp2, you are the man once again!  That solution worked perfectly.  I cannot thank you enough for your help on this.  It saved me hours or time, and also helped consolidate my code down to just a few lines of code.  I had a few lines for each state, but now I parse off the 2 letters and select the state with 1 line of code for all areas.

Thanks!!!!!!

; line below will select area    
    _WD_ExecuteScript($sSession, "PrimeFaces.getWidgetById('frmSearch:scmRegion').selectValue('" & StringLower($areaSel) & "')")

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...