Note that there are some explanatory texts on larger screens.

plurals
  1. POSelenium.IsElementPresent using a Select Option's text (C#)
    primarykey
    data
    text
    <p>I'm using Selenium in C# with Selenium RC to do some automated interaction testing but have come across a stumbling block.</p> <p>Given this HTML:</p> <pre><code>&lt;select id="my-select-list"&gt; &lt;option value="1"&gt;First option&lt;/option&gt; &lt;option value="2"&gt;Second option&lt;/option&gt; &lt;option value="3"&gt;Third option&lt;/option&gt; &lt;option value="4"&gt;Fourth option&lt;/option&gt; &lt;/select&gt; </code></pre> <p>I want to test to make sure that the option "Third Option" is present on the page.</p> <p>All of the following tests have failed, i.e. return false:</p> <pre><code>Selenium.IsElementPresent("//select/option[@label='Third option']") Selenium.IsElementPresent("//select[option='Third option']") Selenium.IsElementPresent("//select[contains(option, 'Third option')]") Selenium.IsElementPresent("//option[contains(., 'Third option')]") Selenium.IsElementPresent("//option[contains(text(), 'Third option')]") </code></pre> <p>Is it a limitation of Selenium (RC / .NET) or is there another way of selecting it?</p> <p>Ps. I know I could test using the option's value but that may change and the text definately won't.</p> <p><strong>EDIT: PEBKAC error</strong></p> <p>Sorry, my bad. Seems selenium was loading a different site than what I thought it was loading.</p> <p>The following XPath queries all work:</p> <pre><code>Selenium.IsElementPresent("//option[text()='Third option']") Selenium.IsElementPresent("//select[option='Third option']") Selenium.IsElementPresent("//option[contains(., 'Third option')]") Selenium.IsElementPresent("//option[contains(text(), 'Third option')]") </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload