I have a site with a <select>
that has more than 100 <option>
s in it, one for every country in the world. My test needs to select one. My current solution - below - takes around 2.5 seconds. I'd like it to be much faster.
findChildrenByLabel :: (WD.WebDriver m, MonadIO m) =>
Text -> Text -> m [WD.Element]
findChildrenByLabel label tagName = do
parentEl <- findFieldByLabel label
WD.findElemsFrom parentEl $ WD.ByTag tagName
findChildByLabelF :: (WD.WebDriver m, MonadIO m) =>
Text -> Text -> (WD.Element -> m Bool) -> m WD.Element
findChildByLabelF label tagName f = do
children <- findChildrenByLabel label tagName
child <- filterM f children
liftIO $ child `shouldSatisfy` ((==1) . length)
return (headEx child)
selectDropdownByLabel :: (WD.WebDriver m, MonadIO m) => Text -> Text -> m ()
selectDropdownByLabel label optionName = do
targetOption <- findChildByLabelF
label "option" (\el -> (== optionName) <$> WD.getText el)
WD.click targetOption
I found this SO answer in Java, but there doesn't seem to be anything like Selenium.Support
or SelectByText
for Haskell.