How can I select multiple web elements from an ordered list using Selenium WebDriver in C#?
I want to do it manually, I would press Ctrl and select multiple options. I want to automate this.
Below is the sample HTML:
<ol id="selectable" class="ui-selectable">
<li class="ui-state-default ui-selectee">1</li>
<li class="ui-state-default ui-selectee">2</li>
<li class="ui-state-default ui-selectee">3</li>
<li class="ui-state-default ui-selectee">4</li>
<li class="ui-state-default ui-selectee">5</li>
<li class="ui-state-default ui-selectee">6</li>
<li class="ui-state-default ui-selectee">7</li>
<li class="ui-state-default ui-selectee">8</li>
<li class="ui-state-default ui-selectee">9</li>
<li class="ui-state-default ui-selectee">10</li>
<li class="ui-state-default ui-selectee">11</li>
<li class="ui-state-default ui-selectee">12</li>
</ol>
Appreciate your time and efforts.
Have you tried using GetElementsByClassName()? Combined with the KeyDown command in the Actions class (See the answer for this question) something like this may work for you...
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Interactions;
var driver = new WebDriver();
var elements = driver.GetElementsByClassName("ui-state-default ui-selectee");
var action = new Actions(driver);
action.KeyDown(Keys.Control);
foreach (var element in elements)
{
// If element properties match your selection
element.Click()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With