Jump to content

How to attach a a variable in the value field of an element using _WD_LOCATOR_ByCSSSelector


Recommended Posts

I'm trying to select a specific option in a dropdown box based on the value of a cell from an excel sheet.

I can make it work when using the script below:

Local $oTest = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, ".page")
    Local $oTest2 = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByCSSSelector, "#main", $oTest)
    Local $oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "mds-select-option[value='Monkey']", $oTest2)
    _WD_ElementAction($sSession, $oTest4, 'click')

Notice that i have put value = 'Monkey', but there are several values from the sheet.

So far, here are my attempts that didnt work.

;Local $oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "mds-select-option[value='']", $oTest2)
                ;_WD_ElementAction($sSession, $oTest4, 'value', $aArray4[$i])
                
                
                ;Local $oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "mds-select-option", $oTest2)
                ;_WD_ElementAction($sSession, $oTest4, 'value', $aArray4[$i])
                
                ;Local $oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "mds-select-option", $oTest2)
                ;_WD_ElementAction($sSession, $oTest4, 'click' = $aArray4[$i])
                
                ;Local $oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "mds-select-option[value='$aArray4[$i]']", $oTest2)
                ;_WD_ElementAction($sSession, $oTest4, 'click')
                
                ;Local $oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "mds-select-option[value=$aArray4[$i]]", $oTest2)  <--- I really thought this one would work but did not.
                ;_WD_ElementAction($sSession, $oTest4, 'click')

 

Link to comment
Share on other sites

2 hours ago, Hermes said:

Local $oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "mds-select-option[value='Monkey']", $oTest2)

Just change this line so that the locator string is dynamic instead of a constant. Like this --

$oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "mds-select-option[value='" & $aArray4[$i] & "']", $oTest2)

 

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