Hi all!
I am attempting a script in Excel using selenium to automate some website testing and ran into a problem with a series of dropdowns.
Not sure what is most helpful so I included everything I could find. Please excuse if there's too much info here. The problem is the number of dropdowns will vary and each "person" is assigned a 10 digit variable. I will have a sheet in the workbook with data so the script will know what relation to choose. The rest of the code to this point is working as anticipated so, I can adapt any code ideas provided, I just can't figure out a smart way to tackle these dropdowns.
Below is what I see using the Inspect function in Chrome. 1000174402 and 1000174429 are the variables assigned to self and spouse, respectively, by the app:
HTML:
Xpath
Full Xpath:
This is how the Selenium Chrome addon sees it on a recording, selecting "Spouse" from the list :
For my own sanity, I've reduced the test to a family structure of married vs unmarried and somewhere between 0-4 children. That gives me a range of 1-20 xpath divs.
For a married couple with 4 kids the pattern looks like this:
I was trying to dodge the variables issues to make this vba more universally functional. So tried to use the Full Xpath:
That's were the runtime error appears. I've included snips of the GUI and the error.
I'm sure there's a better way to tackle this. How would you click through these dropdowns, select the appropriate relationship and avoid having to mess with the variable issue?
Thanks in advance for your help!!
I am attempting a script in Excel using selenium to automate some website testing and ran into a problem with a series of dropdowns.
Not sure what is most helpful so I included everything I could find. Please excuse if there's too much info here. The problem is the number of dropdowns will vary and each "person" is assigned a 10 digit variable. I will have a sheet in the workbook with data so the script will know what relation to choose. The rest of the code to this point is working as anticipated so, I can adapt any code ideas provided, I just can't figure out a smart way to tackle these dropdowns.
Below is what I see using the Inspect function in Chrome. 1000174402 and 1000174429 are the variables assigned to self and spouse, respectively, by the app:
HTML:
HTML:
<select id="page_06_relation_1000174402_to_1000174429" name="relation_1000174402_to_1000174429" aria-required="true" class="tablet:grid-col-6 gi-dropdown__select undefined"><option value="default">Relation</option><option value="19">Child (son or daughter)</option><option value="31">Court-Appointed Guardian</option><option value="53">Domestic partner</option><option value="05">Grandchild (grandson or granddaughter)</option><option value="04">Grandparent (grandfather or grandmother)</option><option value="13">Mother-in-law or Father-in-law</option><option value="03">Parent (father or mother)</option><option value="14">Sibling (brother or sister)</option><option value="11">Son-in-law or Daughter-in-law</option><option value="01">Spouse</option><option value="17">Stepchild (stepson or stepdaughter)</option><option value="16">Stepparent (stepfather or stepmother)</option><option value="15">Ward</option><option value="G9">Other</option></select>
Xpath
Code:
//*[@id="page_06_relation_1000174402_to_1000174429"]
Full Xpath:
Code:
/html/body/div[1]/div/main/div[1]/div/div/div[2]/div[1]/div/form/div[2]/select
This is how the Selenium Chrome addon sees it on a recording, selecting "Spouse" from the list :
Rich (BB code):
"id": "82d2b6c3-c22d-4107-a8c2-ca1674ae7f00",
"comment": "",
"command": "click",
"target": "id=page_06_relation_1000174402_to_1000174429",
"targets": [
["id=page_06_relation_1000174402_to_1000174429", "id"],
["name=relation_1000174402_to_1000174429", "name"],
["css=#page_06_relation_1000174402_to_1000174429", "css:finder"],
["xpath=//select[@id='page_06_relation_1000174402_to_1000174429']", "xpath:attributes"],
["xpath=//div[@id='fhRelationship']/div/form/div[2]/select", "xpath:idRelative"],
["xpath=//select", "xpath:position"]
],
"value": ""
}, {
"id": "ca159432-cfb6-4454-845f-4e3b2f96609b",
"comment": "",
"command": "select",
"target": "id=page_06_relation_1000174402_to_1000174429",
"targets": [],
"value": "label=Spouse"
}, {
For my own sanity, I've reduced the test to a family structure of married vs unmarried and somewhere between 0-4 children. That gives me a range of 1-20 xpath divs.
For a married couple with 4 kids the pattern looks like this:
div1 = Self and does not appear in the GUI | |
test botYHIone is Spouse botYHIone's = div2 | |
test botYHIone is ChildOne botYHIone's = div3 | |
test botYHIone is ChildTwo botYHIone's = div4 | |
test botYHIone is ChildThree botYHIone's = div5 | |
test botYHIone is ChildFour botYHIone's = div6 | |
div7 = Spouse and does not appear in the GUI | |
Spouse botYHIone is ChildOne botYHIone's = div8 | |
Spouse botYHIone is ChildTwo botYHIone's = div9 | |
Spouse botYHIone is ChildThree botYHIone's = div10 | |
Spouse botYHIone is ChildFour botYHIone's = div11 | |
div12 = ChildOne and does not appear in the GUI | |
ChildOne botYHIone is ChildTwo botYHIone's = div13 | |
ChildOne botYHIone is ChildThree botYHIone's = div14 | |
ChildOne botYHIone is ChildFour botYHIone's = div15 | |
div16 = ChildTwo and does not appear in the GUI | |
ChildTwo botYHIone is ChildThree botYHIone's = div17 | |
ChildTwo botYHIone is ChildFour botYHIone's = div18 | |
div19 = ChildThree and does not appear in the GUI | |
ChildThree botYHIone is ChildFour botYHIone's = div20 |
I was trying to dodge the variables issues to make this vba more universally functional. So tried to use the Full Xpath:
VBA Code:
bot.FindElementByXPath("[/html/body/div[1]/div/main/div[1]/div/div/div[2]/div[1]/div/form/div[2]/select]").Click
That's were the runtime error appears. I've included snips of the GUI and the error.
I'm sure there's a better way to tackle this. How would you click through these dropdowns, select the appropriate relationship and avoid having to mess with the variable issue?
Thanks in advance for your help!!
Attachments
Last edited by a moderator: