jasontj Posted December 12, 2023 Posted December 12, 2023 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') Thanks in advance for any guidance on this issue. Jason
Danp2 Posted December 12, 2023 Posted December 12, 2023 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 Latest Webdriver UDF Release Webdriver Wiki FAQs
jasontj Posted December 13, 2023 Author Posted December 13, 2023 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.
Danp2 Posted December 13, 2023 Posted December 13, 2023 AFAICS, you need to click on either of these -- <div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default"> or <label for="f7143acc-c266-446c-b7d6-f07bd8cf16b4">Alabama</label> Those are the elements that have the associated click events. Latest Webdriver UDF Release Webdriver Wiki FAQs
Solution Danp2 Posted December 13, 2023 Solution Posted December 13, 2023 Here is the information on the client-side APIs. You should be able to execute the following with _WD_ExecuteScript to select the Alabama option -- PrimeFaces.getWidgetById('frmSearch:scmRegion').selectValue('al') Latest Webdriver UDF Release Webdriver Wiki FAQs
jasontj Posted December 13, 2023 Author Posted December 13, 2023 @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) & "')")
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now