!!

Welcome to Selenium Webdriver Forum

As a web user you can read and search through forum content. Once you have registered and signed you can post topics, post replies, set up watch lists, modify forum settings, and use private messaging.

Author Topic: check that a value is selected by default in a drop down list  (Read 1211 times)

Offline kc

  • Selenium User
  • *
  • Posts: 12
Hi. I want to check that the default value("Excess Stock Distribution") that is displayed in the drop down menu is the correct one.

the code is:
<select id="stockDistributionOption" class="tracker-input-modifiable" onchange="updateLabels();">
<option value="1" selected="selected">Excess Stock Distribution</option>
<option value="2">Stock New Branch</option>
</select>

I tried :

 Assert.isTrue(driver.findElement(By.tagName("option")).isSelected(), "Stock New Branch");

or even attempting something like that:

Select dList = new Select((driver.findElement(By.id("stockDistributionOption"))));
        List<WebElement> opt = dList.getOptions();
        for(WebElement we:opt){
            boolean match = false;
             if (opt.get(1).isSelected()){

                    match = true;
                }

            Assert.isTrue(match);
        }

Can someone please help?

Thanks

Offline Selenium Webdriver Admin

  • Administrator
  • Full Member
  • *****
  • Posts: 242
Re: check that a value is selected by default in a drop down list
« Reply #1 on: March 19, 2013, 11:27:27 PM »
Code: [Select]
public string GetSelectedLabel(string xpath)
        {
            string text = "";

            if (IsElementPresent("//select[@id='stockDistributionOption']/option[@selected]"))
            {
                text = GetText("//select[@id='stockDistributionOption']/option[@selected]");
            }
            return text;
        }

For GetText
Code: [Select]
public string GetText(string xpath)
        {
            string text = "";
            if (IsElementPresent(xpath))
            {
                text = driver.FindElement(By.XPath(xpath)).Text;
            }
            return text;
        }

Let me know if this helps

 

Related Topics

  Subject / Started by Replies Last post
1 Replies
547 Views
Last post February 22, 2012, 06:08:07 PM
by Chad Woolley
2 Replies
2381 Views
Last post March 27, 2012, 09:14:13 PM
by Simon Stewart
4 Replies
2292 Views
Last post March 29, 2012, 07:39:15 PM
by Anuja Jain
10 Replies
1197 Views
Last post April 03, 2012, 03:57:29 PM
by Benjamin Hawkes-Lewis
1 Replies
2465 Views
Last post April 10, 2012, 11:08:04 PM
by Natraj Yerram
2 Replies
774 Views
Last post May 03, 2012, 07:14:09 PM
by Mike Riley
drop down list

Started by shankar kurella Selenium RC - Selenium 1.0

4 Replies
1117 Views
Last post May 03, 2012, 11:00:07 PM
by shankar kurella