Jump to content

Unable to target select options using AutoIt in Google Chrome


Recommended Posts

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.

Link to comment
Share on other sites

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])

 

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...