Reputation: 2050
I try to click on the select menu and to choose the element:
<div id="_desktop_currency_selector">
<div class="currency-selector dropdown js-dropdown">
<span>Currency:</span>
<span class="expand-more _gray-darker hidden-sm-down" data-toggle="dropdown" aria-expanded="false">UAH ₴</span>
<a data-target="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="hidden-sm-down">
<i class="material-icons expand-more"></i>
</a>
<ul class="dropdown-menu hidden-sm-down" aria-labelledby="dLabel" style="display: none;">
<li>
<a title="EUR" rel="nofollow" href="http://prestashop-automation.qatestlab.com.ua/ru/?SubmitCurrency=1&id_currency=2" class="dropdown-item">EUR €</a>
</li>
<li class="current">
<a title="UAH" rel="nofollow" href="http://prestashop-automation.qatestlab.com.ua/ru/?SubmitCurrency=1&id_currency=1" class="dropdown-item">UAH ₴</a>
</li>
<li>
<a title="USD" rel="nofollow" href="http://prestashop-automation.qatestlab.com.ua/ru/?SubmitCurrency=1&id_currency=3" class="dropdown-item">USD $</a>
</li>
</ul>
<select class="link hidden-md-up">
<option value="http://prestashop-automation.qatestlab.com.ua/ru/?SubmitCurrency=1&id_currency=2">EUR €</option>
<option value="http://prestashop-automation.qatestlab.com.ua/ru/?SubmitCurrency=1&id_currency=1" selected="selected">UAH ₴</option>
<option value="http://prestashop-automation.qatestlab.com.ua/ru/?SubmitCurrency=1&id_currency=3">USD $</option>
</select>
</div>
</div>
My way:
WebElement element1 = driver.findElement(By.className("link hidden-md-up"));
Select dropList = new Select(element1);
// debug sysout
dropList.getOptions().forEach(p -> System.out.println(p.getText()));
In result I get this exception:
org.openqa.selenium.InvalidSelectorException: invalid selector: Compound class names not permitted
selenium
?Upvotes: 0
Views: 808
Reputation: 2813
It will not work with select class because, its not pure drop-down, its un-ordered lists of currencies
you need to open drop down by clicking on it, do something like this
driver.driver.findElement(By.xpath(".//div[@class='currency-selector dropdown js-dropdown']/a[@data-toggle='dropdown']")).click();
with this drop down list will open, now get individual element from list using xpath-
.//a[@title='USD'] or .//a[@title='USD']/parent::li
Upvotes: 2
Reputation: 20456
The exception is due to the multiple classes used in the selector. Change your selector to use single class or a cssSelector. See example below. Check if these selectors return unique(required) element.
WebElement element1 = driver.findElement(By.className("hidden-md-up"));
OR
WebElement element1 = driver.findElement(By.cssSelector(".link.hidden-md-up"));
Upvotes: 2