This is how i resolved my issue of not consistently select a value on a
dropdown, having items not visible because its at the bottom of the
dropdown. THis can be shorten by using iList or Array..
Public Sub doDropDownSelect(by As By, xpath As String, Optional
valueToSelect As String = "")
'USAGE: dropDownSelect(dropdownid,"//*[@id='dropdown
id']/a/span","item in string")
Try
If Sync(driver, by) Then
Sleep(1000)
ClickElement(by)
Dim myElement As IWebElement = driver.FindElement(by)
Dim myXpath = String.Format("//*[@id='{0}']/a/span",
by.ToString)
Dim myElements As
System.Collections.ObjectModel.ReadOnlyCollection(Of IWebElement) =
myElement.FindElements(by.TagName("li"))
Dim r As New Random
Dim i As Integer = r.Next(0, myElements.Count - 1)
Dim j As Integer = 0
Dim k As Integer = 0
Dim mySelectedValue As String =
driver.FindElement(by.XPath(String.Format(xpath))).Text
'Get the index current selected value if any
If mySelectedValue <> "choose..." Then
For Each e As IWebElement In myElements
If e.Text = mySelectedValue Then
Exit For
Else
j = j + 1
End If
Next
End If
'mySelectedValue = myElements.item(j)
If valueToSelect = "" Then
valueToSelect = myElements.Item(i).Text
Else
For Each e As IWebElement In myElements
k = k + 1
If e.Text.Trim = valueToSelect.Trim Then
'valuetoselect = myelements.item(k)
i = k
Exit For
End If
Next
End If
Dim t As Boolean = myElements.Item(i).Displayed
Dim y As String = myElements.Item(i).Text
While myElements.Item(i).Displayed <> True
If j > i Then
Dim Action = New
OpenQA.Selenium.Interactions.Actions(driver).SendKeys(Keys.ArrowUp)
Action.Perform()
Else
Dim Action = New
OpenQA.Selenium.Interactions.Actions(driver).SendKeys(Keys.ArrowDown)
Action.Perform()
End If
If valueToSelect = myElements.Item(i).Text Then
Exit While
End If
End While
myElements.Item(i).Click()
End If
Catch ex As Exception
Throw ex
End Try
End Sub
On Wednesday, July 9, 2014 7:06:28 AM UTC-7, Sudhansu Sekhar panda wrote:
Hi All,
I have a scenario to verify...
Scenario: There is a dropdwon, when i will click on that drop down the
dropdown box will show up with the all the dropdown items..And when i will
click outside that drop down box will disappear...Is there anyway to
automate this in Selenium WebDriver?
Thanks,
Sudhansu
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/selenium-users/2f943092-83d2-4d19-a506-718189352bfb%40googlegroups.com.For more options, visit
https://groups.google.com/d/optout.