Javascript 测定硒中常见元素定位器的数量

Javascript 测定硒中常见元素定位器的数量,javascript,python,selenium,Javascript,Python,Selenium,我正在尝试使用for循环动态选择一个元素。为了确定范围,我需要知道元素的计数,如何在selenium(python)中做到这一点。我需要为此执行javascript吗 # count = how?? for i in range(1, count): #element index start at 1 xpath = '//div[@class="form-group"]/select/option['+str(i)+']' if self.find_eleme

我正在尝试使用for循环动态选择一个元素。为了确定范围,我需要知道元素的计数,如何在selenium(python)中做到这一点。我需要为此执行javascript吗

# count = how??

for i in range(1, count): #element index start at 1
        xpath = '//div[@class="form-group"]/select/option['+str(i)+']'
        if self.find_elements_by_xpath(xpath).text == driver_name:
            self.find_elements_by_xpath(xpath).click()

我相信您正在尝试在一个选择字段中不计算任何选项,如果是这种情况,请尝试此选项

from selenium.webdriver.support.select import Select as WebDriverSelect
s_element = WebDriverSelect(driver.find_elements_by_xpath(your_xpath_expression))
count = len(s_element.options)

我相信您正在尝试在一个选择字段中不计算任何选项,如果是这种情况,请尝试此选项

from selenium.webdriver.support.select import Select as WebDriverSelect
s_element = WebDriverSelect(driver.find_elements_by_xpath(your_xpath_expression))
count = len(s_element.options)