0

I am dealing with a Combo box, have to verify that an Item does not exist in combo box. lets say Combo box has following 4 values

Apple

Ball

Cat

Dog

and I want to verify that Elephant does not exist in combo box..

Any help would be appreciated

Br Sara

Laurent Bristiel
  • 6,819
  • 34
  • 52
Sara
  • 585
  • 7
  • 12
  • 22
  • possible duplicate of [Selenium WebDriver to select combo-box item?](http://stackoverflow.com/questions/6924550/selenium-webdriver-to-select-combo-box-item) – plsgogame Oct 24 '13 at 08:44

3 Answers3

0

OK, I have found a solution myself. Page Should Not Contain Element , keyword helps and use as follow Page Should Not Contain Element "Xpath" (use Xpath if you have 2 argument) xpath=//*[@id="InvestmentCollectionForm:selectedInvestmentId"]/../../td/select/option[@value='26']

Sara
  • 585
  • 7
  • 12
  • 22
0

Run Keyword And Expect Error is your friend. So try to select Elephant from the combo box and expect that to fail.

Harri
  • 2,692
  • 2
  • 21
  • 25
0

You can point combo element, get all values by tag name and search by foreach if value is there. C#

public bool IsValuePresentInCombo(string comboId, string comboValue)
{
    var combo = Driver.FindElement(By.Id(comboId));
    foreach (var item in combo.FindElements(By.TagName("option")))
    {
        if (item.GetAttribute("value") == comboValue)
        {
            return true;
        }
        return false;
    }
}
Bart Wojtala
  • 1,290
  • 9
  • 7