Incantation Posted March 2, 2021 Posted March 2, 2021 I'm trying to select a specific option in a dropdown list using AutoIt. So far, i have the following HTML codes: <label for="cars">Choose a car:</label> <select name="cars" class="cars"> <option class="volvo" value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option class="audi" value="audi">Audi</option> and AutoIt script: Local $oSettingsUISR = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByTagName, "select") _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//select[contains(@class,'cars') or contains(text()')]") $test3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[contains(@class,'cars') or contains(text(),'Choose section')]") $test4 = _WD_ElementAction($sSession, $test3, 'click') _WD_ElementOptionSelect($sSession, $test4, $aArray4[$i]) The script above selects the dropdown, but i am wanting to click on a specific option, say for sample "audi". So i did: Local $oSettingsUISR = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByTagName, "select") _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//select[contains(@class,'cars audi') or contains(text()')]") $test3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[contains(@class,'cars audi') or contains(text(),'Choose section')]") $test4 = _WD_ElementAction($sSession, $test3, 'click') _WD_ElementOptionSelect($sSession, $test4, $aArray4[$i]) But it doesnt seems to click Audi. Appreciate any help that i can get.
Incantation Posted March 2, 2021 Author Posted March 2, 2021 This has been sorted. I just realized that i was targeting an incorrect element. For reference, this has solved my issue. Local $oSettingsUISR = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByTagName, "select") _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//option[contains(@class,'audi') or contains(text()')]") $test3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//option[contains(@class,'audi') or contains(text(),'Choose section')]") $test4 = _WD_ElementAction($sSession, $test3, 'click') _WD_ElementOptionSelect($sSession, $test4, $aArray4[$i])
Danp2 Posted March 2, 2021 Posted March 2, 2021 @Incantation Does this line even work? Your xpath looks funny -- _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//option[contains(@class,'audi') or contains(text()')]") Latest Webdriver UDF Release Webdriver Wiki FAQs
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