0

I am in a situation where I have to expand the drop down and from the list of values after expansion, I have to select one value.

Could you please help in this?

Below is the code I have used so far:

List<WebElement> elements = driver.findElement(By.id("Some Value"));

for (WebElement element: elements)
{
    new Actions(driver).sendKeys(Keys.Arrow_Down).perform();
        if(Element.getText().equals("Cliam Document"))
        {
            element.click();
        }
}
4
  • 2
    Can you provide the HTML part now? Commented May 17, 2017 at 12:16
  • 2
    @vinod plz add html code or some image related to this . Its creating confusion why are u using action class here Commented May 17, 2017 at 12:49
  • Would it give any help if i share code through inspect element? Commented May 17, 2017 at 14:56
  • <div class="dijitReset dijitInputField dijitInputContainer"><input class="dijitReset dijitInputInner" autocomplete="off" data-dojo-attach-point="textbox,focusNode" role="textbox" aria-autocomplete="both" aria-required="true" tabindex="0" id="ecm_widget_AddContentItemGeneralPane_0_entryTemplateSelector" value="" aria-invalid="true" type="text"><span class="dijitPlaceHolder dijitInputField">Enter or select an entry template</span><input name="ecm_widget_AddContentItemGeneralPane_0_entryTemplateSelector" value="" type="hidden"></div> Commented May 19, 2017 at 4:37

3 Answers 3

1

You can use below code :

to use the dropdownlist

   Select select1 = new Select(driver.findElement(By.id("your identifier")));
    select1.selectByVisibleText("Cliam Document");
Sign up to request clarification or add additional context in comments.

3 Comments

If the above solution does not work, then please double-check the drop-down value - are you sure it's not "Claim Document" rather than "Cliam Document?" The method mohamed faisal showed is the correct method, but it won't work if the text you're looking for is not there.
I tried using this also. but no select class in HTML code.only input tag is present, Any help.
select class is in your java code not in the page HTML code you only need to get your element id replace "your identifier" with it
0

You can select a values from Drop down in 3 ways,

  1. By using selectByVisibleText()
  2. By using selectByValue()
  3. By using selectByIndex()

In your case no need to use Action() class. You can use any method from above.

Check this Code:

Select se = new Select(driver.findElement(By.id("your ID")));
se.selectByIndex(your preferred index value);

1 Comment

Thanks Sandeep Kumar, but i could not find select class in HTML code. please suggest another way to access drop down.
0

Scenarios:
1. Store value into string where you want to perform click operation.
2. Store all Drop down values into List.
3. Using For each loop store all values into WebElement.
4. Get Text of each and every one value and store into string.
5. Compare each and every Actual string with Expected String.
6. If Expected string found within for each loop then click on WebElement.

String Expected_String = "Test";
List<WebElement> elements = driver.findElement(By.id("Some Value"));
for (WebElement element : elements) 
{
    String value = element.getText();
    if (value.equalsIgnoreCase( Expected_String)) 
    {
        element.click();
        break;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.