无法参考下拉列表中的选项(Selenium&;Django)

无法参考下拉列表中的选项(Selenium&;Django),django,list,selenium,selection,Django,List,Selenium,Selection,我的下拉列表: <select id="id_category" name="category"> <option value="" selected="selected">---------</option> <option value="1">Category #1</option> <option value="2">Test1</option> </select> 我不确定,但我认为Sele

我的下拉列表:

<select id="id_category" name="category">
<option value="" selected="selected">---------</option>
<option value="1">Category #1</option>
<option value="2">Test1</option>
</select>
我不确定,但我认为Selenuim只看到第一个选项,这个选项带有(selected=“selected”)

这是我收到的错误消息:

ERROR: test_create_blog_entry_admin (tests.AdminTest)
Test for adding blog entry
----------------------------------------------------------------------
Traceback (most recent call last):
  File "F:\projekty\careerguide\careerguide\careerguide\ft\tests.py", line 66, in test_create_blog_entry_admin    self.browser.find_element_by_xpath("//select[@id='id_category']/option[text(
)='Test1']").click()
  File "F:\Python27\lib\site-packages\selenium-2.41.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 223, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "F:\Python27\lib\site-packages\selenium-2.41.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 655, in find_element
    {'using': by, 'value': value})['value']
  File "F:\Python27\lib\site-packages\selenium-2.41.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 166, in execute
    self.error_handler.check_response(response)
  File "F:\Python27\lib\site-packages\selenium-2.41.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 164, in check_response
    raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: u'Unable to locate element: {"method":"xpath","selector":"//select[@id=\'id_category\']/option[text()=\'Test1\']"}' ; Stacktrace:
    at FirefoxDriver.prototype.findElementInternal_ (file:///c:/users/konrad/appdata/local/temp/tmpfxvjan/extensions/fxdriver@googlecode.com/components/driver_component.js:8905)
    at FirefoxDriver.prototype.findElement (file:///c:/users/konrad/appdata/local/temp/tmpfxvjan/extensions/fxdriver@googlecode.com/components/driver_component.js:8914)
    at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/konrad/appdata/local/temp/tmpfxvjan/extensions/fxdriver@googlecode.com/components/command_processor.js:10884)
    at DelayedCommand.prototype.executeInternal_ (file:///c:/users/konrad/appdata/local/temp/tmpfxvjan/extensions/fxdriver@googlecode.com/components/command_processor.js:10889)
    at DelayedCommand.prototype.execute/< (file:///c:/users/konrad/appdata/local/temp/tmpfxvjan/extensions/fxdriver@googlecode.com/components/command_processor.js:10831)
错误:test\u create\u blog\u entry\u admin(tests.AdminTest)
添加博客条目的测试
----------------------------------------------------------------------
回溯(最近一次呼叫最后一次):
文件“F:\projekty\careerguide\careerguide\careerguide\ft\tests.py”,第66行,在test\u create\u blog\u entry\u admin self.browser中。通过xpath查找元素(//选择[@id='id\u category']/选项[text](
)='Test1']')。单击()
文件“F:\Python27\lib\site packages\selenium-2.41.0-py2.7.egg\selenium\webdriver\remote\webdriver.py”,第223行,按xpath查找元素
返回self.find_元素(by=by.XPATH,value=XPATH)
文件“F:\Python27\lib\site packages\selenium-2.41.0-py2.7.egg\selenium\webdriver\remote\webdriver.py”,第655行,在find_元素中
{'using':by'value':value})['value']
文件“F:\Python27\lib\site packages\selenium-2.41.0-py2.7.egg\selenium\webdriver\remote\webdriver.py”,执行中第166行
self.error\u handler.check\u响应(响应)
文件“F:\Python27\lib\site packages\selenium-2.41.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py”,第164行,在check\u响应中
引发异常类(消息、屏幕、堆栈跟踪)
NoSuchElementException:Message:u'无法定位元素:{“方法”:“xpath”,“选择器”:“//select[@id=\'id\u category\']/option[text()=\'Test1\']“}”;堆栈跟踪:
在FirefoxDriver.prototype.findelement内部(file:///c:/users/konrad/appdata/local/temp/tmpfxvjan/extensions/fxdriver@googlecode.com/components/driver_component.js:8905)
在FirefoxDriver.prototype.findElement(file:///c:/users/konrad/appdata/local/temp/tmpfxvjan/extensions/fxdriver@googlecode.com/components/driver_component.js:8914)
在DelayedCommand.prototype.executeInternal\uh处(file:///c:/users/konrad/appdata/local/temp/tmpfxvjan/extensions/fxdriver@googlecode.com/components/command_processor.js:10884)
在DelayedCommand.prototype.executeInternal\u(file:///c:/users/konrad/appdata/local/temp/tmpfxvjan/extensions/fxdriver@googlecode.com/components/command_processor.js:10889)
在DelayedCommand.prototype.execute/<(file:///c:/users/konrad/appdata/local/temp/tmpfxvjan/extensions/fxdriver@googlecode.com/components/command_processor.js:10831)

在第一个示例中,您应该使用id而不是名称

self.browser.find_element_by_xpath("//select[@id='id_category']/option[text()='Test1']").click()

在第二个示例中找不到任何问题。尝试
选项。选择()
。它出现在早期版本的webdriver中。不确定您使用的是哪一个。

在第一个示例中,您应该使用id而不是name

self.browser.find_element_by_xpath("//select[@id='id_category']/option[text()='Test1']").click()

在第二个示例中找不到任何问题。尝试
选项。选择()
。它出现在早期版本的webdriver中。不确定您使用的是哪一个。

在第一个示例中,您应该使用id而不是name

self.browser.find_element_by_xpath("//select[@id='id_category']/option[text()='Test1']").click()

在第二个示例中找不到任何问题。尝试
选项。选择()
。它出现在早期版本的webdriver中。不确定您使用的是哪一个。

在第一个示例中,您应该使用id而不是name

self.browser.find_element_by_xpath("//select[@id='id_category']/option[text()='Test1']").click()

在第二个示例中找不到任何问题。尝试
选项。选择()
。它出现在早期版本的webdriver中。不确定您使用的是哪一个。

我建议使用
Select()

from selenium.webdriver.support.select import Select

select = Select(driver.find_element_by_id("id_category"))
select.select_by_visible_text("Test1")

我建议使用
Select()

from selenium.webdriver.support.select import Select

select = Select(driver.find_element_by_id("id_category"))
select.select_by_visible_text("Test1")

我建议使用
Select()

from selenium.webdriver.support.select import Select

select = Select(driver.find_element_by_id("id_category"))
select.select_by_visible_text("Test1")

我建议使用
Select()

from selenium.webdriver.support.select import Select

select = Select(driver.find_element_by_id("id_category"))
select.select_by_visible_text("Test1")

我的帖子结束了,我是新用户,我不能回答我的问题:我的帖子结束了,我是新用户,我不能回答我的问题:我的帖子结束了,我是新用户,我不能回答我的问题:我的帖子结束了,我是新用户,我不能回答我的问题:PI得到了这个错误:回溯(最后一次调用):文件“F:\projekty\careerguide\careerguide\careerguide\ft\tests.py”,第68行,在测试创建博客条目管理选择中。通过可见文本(“Test1”)选择文件“F:\Python27\lib\site packages\selenium-2.41.0-py2.7.egg\selenium\webdriver\support\select.py”,第136行,在select_by_visible_text中引发NoSuchElementException(“无法找到具有可见文本的元素:%s”%text)NoSuchElementException:Message:“无法找到具有可见文本的元素:Test1”,并且您确定有一个带有文本“Test1”的选项,正是在您正在处理的
Select
元素中?我得到了这个错误:回溯(最近一次调用):文件“F:\projekty\careerguide\careerguide\careerguide\ft\tests.py”,第68行,在test\u create\u blog\u entry\u admin Select中“F:\Python27\lib\site packages\selenium-2.41.0-py2.7.egg\selenium\webdriver\support\select.py”,select_by_visible_文本中的第136行引发NoSuchElementException(“无法找到具有可见文本的元素:%s”%text)NoSuchElementException:Message:'无法找到具有可见文本的元素:Test1',并且您确信您有一个文本为“Test1”的选项,正是您正在处理的
Select
元素中的选项?我得到了以下错误:回溯(最近一次调用):文件“F:\projekty\careerguide\careerguide\careerguide\ft\tests.py”,第68行,在test\u create\u blog\u entry\u admin select.select by\u visible\u text(“Test1”)文件“F:\Python27\lib\site packages\selenium-2.41.0-py2.7.egg\selenium\webdriver\support\select.py”第136行,在select by\u visible\u text中引发NoSuchElementException(“找不到具有可见文本的元素:%s”%text)NoSuchElementException:Message:“找不到文本可见的元素:Test1”,并且您确信您有一个文本为“Test1”的选项,正是您正在处理的
Select
元素中的选项?我得到了以下错误:回溯(最近一次调用):文件“F:\projekty\careerguide\careerguide\careerguide\ft\tests.py”,第68行,在测试\u创建\u博客\u条目\u管理选择中。选择\u按\u可见\u文本