Below is the code of bootstrap drop-down. After selecting any value from the drop down the tick mark '✓' is also getting selected.
<ul style="max-height:48px;margin:0px 0px 0px 0px;" aria-expanded="false" aria-activedescendant="item1520752761987-1" aria-label="Select your size" title="Select your size" role="listbox" tabindex="0">
<li id="item1520752761987-1" class="selected" role="option" style="width: 52px;">
--
<span class="checked" aria-hidden="true"> ✓</span>
</li>
<li id="item1520752761987-2" role="option" data-value="248" style="width: 52px;">7</li>
<li id="item1520752761987-3" role="option" data-value="304" style="width: 52px;">8</li>
<li id="item1520752761987-4" role="option" data-value="306" style="width: 52px;">9</li>
<li id="item1520752761987-5" role="option" data-value="278" style="width: 52px;">10</li>
<li id="item1520752761987-6" role="option" data-value="280" style="width: 52px;">11</li>
<li id="item1520752761987-7" role="option" data-value="282" style="width: 52px;">12</li>
<li id="item1520752761987-8" role="option" data-value="284" style="width: 52px;">13</li>
<li id="item1520752761987-9" role="option" data-value="285" style="width: 52px;">14</li>
<li id="item1520752761987-10" role="option" data-value="286" style="width: 52px;">15</li>
</ul>
Unable to select values from the drop down. Below, is the selenium Java code that i used.
List<WebElement> dd_menu=driver.findElements(By.xpath("//ul[@title='Select your size']//li"));
for(int i=0;i<dd_menu.size();i++)
{
WebElement element=dd_menu.get(i);
String val=element.getAttribute("innerHTML");
if(val.contentEquals("11"))
{
element.click();
}
//System.out.println("Values From Dropdown : "+val);
}
driver.findElement(By.xpath(".//*[@id='product-addtocart-button']")).click();
}
The above selenium java code for clicking bootstrap dropdown did not work...i need help
Getting the error message in eclipse given below:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//span[@class='checked']//parent::li[@id='item1520579060429-1']"} Command duration or timeout: 48 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35' System info: host: 'VG-IT-LAP-104', ip: '192.168.1.100', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_79' *** Element info: {Using=xpath, value=//span[@class='checked']//parent::li[@id='item1520579060429-1']} Session ID: 2ca11707-7e86-4811-a76b-b7461d3dfb92 Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=33.0.3}]
Tried different combination of dynamic xpaths given below, but still did not work:
//li[contains(@id,'item1520491614103-8')]//following::span[@class='checked']
//li[contains(.,'13')]
//span[@class='checked']//parent::li[@id='item1520579060429-1']
Can you please guide me where it went wrong..if my xpath is incorrect to select any value from the drop down..please advise with a correct xpath