2
votes

Hi I am new to selenium via VBA, I am trying to select the dropdown and from the dropdown I need to select a option which is checkbox. Unfortunately I cannot share the link.

I have trie few codes but it does not work, below are the code I tried

bot.FindElementByXPath("//*[contains(text(),'GT - ALL')]").Click

Here is the web element

<div class="form-group">
<label for="billerId"> Mid </label><br>
<select name="billerId" id="billerId" class="billerId form-control" multiple="multiple" style="display: none;">
<option value="7">(7) Pay</option>
<option value="11">(11)</option>
<option value="GT1">(1) GT - ALL</option>
<option value="GT7">(7) GT - S1- LB</option>
<option value="GT8">(8) GT - S2 - LB</option>
<option value="GT9">(9) GT - S3</option>
<option value="GT6">(6) GT Whistle</option>
<option value="GT4">(4) GT -LB</option>
<option value="1">(1) Main - PP (2)</option>
<option value="4">(4) MTEST</option>
<option value="2">(2) test</option>
<option value="12">(12) RR1</option>
<option value="10">(10) RR Data</option>
<option value="8">(8) RR 2Mid</option>
<option value="9">(9) RR 3</option>
<option value="6">(6) Silver New PP </option>
<option value="5">(5) SILVER </option>
<option value="3">(3) Strike</option>
</select>
<div class="ms-parent billerId form-control"><button type="button" class="ms-choice"><span class="placeholder">All</span><div class=""></div></button>
<div class="ms-drop bottom" style="display: none;">
  <div class="ms-search"><input type="text" autocomplete="off" autocorrect="off" autocapitilize="off" spellcheck="false"></div>
  <ul style="max-height: 250px;">
    <li class="ms-select-all"><label><input type="checkbox" data-name="selectAllbillerId">[Select All]</label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="7"><span>(7) </span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="11"><span>(11) </span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="GT1"><span>(1) GT - ALL</span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="GT7"><span>(7) GT - LB</span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="GT8"><span>(8) GT - S2 - 02/11/17 LB</span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="GT9"><span>(9) GT - S3</span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="GT6"><span>(6) GT Whistle</span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="GT4"><span>(4) GT -LB</span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="1"><span>(1) Main - PP (2)</span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="4"><span>(4) MTEST</span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="2"><span>(2) test</span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="12"><span>(12) RR1</span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="10"><span>(10) RR Data</span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="8"><span>(8) RR 2Mid</span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="9"><span>(9) RR 3</span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="6"><span>(6) Silver New PP </span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="5"><span>(5) SILVER </span></label></li>
    <li class="" style="false"><label class=""><input type="checkbox" data-name="selectItembillerId" value="3"><span>(3) Strike</span></label></li>
    <li class="ms-no-results" style="display: none;">No matches found</li>
  </ul>
</div>

2
Please explain what doesn't work means? - QHarr

2 Answers

2
votes

There appears to be two elements with that xpath when you use the * to identify the selector to target. Since this returns more than one element it is in a list and so you cannot call click on it.

In order for the click to work you need to only get the element you want to click. Not sure which one is the button but these are the explicit xpaths for both:

//option[contains(text(), 'GT - ALL')] 

Or

//span[contains(text(), 'GT - ALL')]
1
votes

You can use an attribute = value css selector which is faster than xpath. Note that text value appears to be: (1) GT - ALL

Your dropdown and checkboxes are distinct.


input checkbox element (indicated by type attribute with value checkbox and that is part of an input tag element)

For the checkbox you can use

bot.findElementByCss("input[type=checkbox][value='GT1']").click

You can likely shorten that to:

bot.findElementByCss("input[value='GT1']").click

dropdown (indicated by parent select tag and child option tag elements):

There is a non checkbox which you would use the following for:

bot.findElementByCss("option[value='GT1']").click

Or

bot.findElementByCss("option[value='GT1']").Selected = True

You can swop the GT1 for other values if required.