Not able to select value from dropdown
Posted: Thu Mar 31, 2016 8:12 pm
Hi, I have a dropdown with 7 values. When ever, I am trying to select a value from dropdown by using a parameter in xpath for the value, It is always selecting the first value from dropdown. If i use exact value instead of parameter in the xpath, it is selecting the exact value. The problem is when I include a parameter in the xpath. I have the xpath and function below. Please help me in resolving this.
MetricSelection = body//ul[@class='x-list-plain']/li[@innertext~'Digital Album'] -- This is working
MetricSelection = body//ul[@class='x-list-plain']/li[@innertext~$objMetricName] -- Always selecting the first value from dropdown if i use this xpath with parameter instead of exact value (I am passing the parameter value as an argument to the function.
Public Shared Sub SelectMetric(objMetricName as String)
Try
repo.MediaViewQC.MetricsDropdown.EnsureVisible
repo.MediaViewQC.MetricsDropdown.Click
report.Log(reportlevel.Success, "Metrics dropdown button is clicked")
If repo.MediaViewQC.MetricSelectionInfo.Exists Then
repo.MediaViewQC.MetricSelection.Focus
repo.MediaViewQC.MetricSelection.Click
report.Log(reportlevel.Success, SelectedMetric & "Metric is selected")
Else
report.Log(reportlevel.Failure, "Metric is not selected")
End If
Else
report.Log(reportlevel.Failure, "Metrics dropdown button is not clicked")
End If
Catch e As Exception
report.Log(reportlevel.Failure, "Not able to select metric")
throw
End Try
End Sub
MetricSelection = body//ul[@class='x-list-plain']/li[@innertext~'Digital Album'] -- This is working
MetricSelection = body//ul[@class='x-list-plain']/li[@innertext~$objMetricName] -- Always selecting the first value from dropdown if i use this xpath with parameter instead of exact value (I am passing the parameter value as an argument to the function.
Public Shared Sub SelectMetric(objMetricName as String)
Try
repo.MediaViewQC.MetricsDropdown.EnsureVisible
repo.MediaViewQC.MetricsDropdown.Click
report.Log(reportlevel.Success, "Metrics dropdown button is clicked")
If repo.MediaViewQC.MetricSelectionInfo.Exists Then
repo.MediaViewQC.MetricSelection.Focus
repo.MediaViewQC.MetricSelection.Click
report.Log(reportlevel.Success, SelectedMetric & "Metric is selected")
Else
report.Log(reportlevel.Failure, "Metric is not selected")
End If
Else
report.Log(reportlevel.Failure, "Metrics dropdown button is not clicked")
End If
Catch e As Exception
report.Log(reportlevel.Failure, "Not able to select metric")
throw
End Try
End Sub