I am trying to get all elements within a drop down and print the total count. Here's the code, which I have written for this.
import unittest
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
class dropdown(unittest.TestCase):
def setUp(self):
self.driver=webdriver.Chrome()
def test_selectmethod(self):
driver=self.driver
driver.get("http://magento-demo.lexiconn.com/")
driver.find_element_by_xpath("//*[@id='select-language']").click()
dropdown=Select(driver.find_element_by_xpath("//*[@id='select-language']"))
print str(len(dropdown)+ "products found"
for i in dropdown:
print(i.text)
def tearDown(self):
self.driver.close()
However, this throws error while printing str(len(dropdown).
dropdown=Select(driver.find_element_by_xpath("//*[@id='select-language']"))should return a select element. You have to get all the options element within select element usingfindelements(in C#, use equivalent for python).ReadOnlyCollection<IwebElements>, on which you should be able to use.count()to get the count. If it returns zero, then xpath may have to modify to get correct value.