Мой выпадающий список:не может ссылаться на опции в выпадающем списке (Селен && Джанго)
<select id="id_category" name="category">
<option value="" selected="selected">---------</option>
<option value="1">Category #1</option>
<option value="2">Test1</option>
</select>
Я хотел сказать, селеном выбрать Test1, я старался каждый вариант я нашел в Интернете, но это просто не работает ..
Вот примеры я пытавшиеся:
#first example
self.browser.find_element_by_xpath("//select[@name='id_category']/option[text()='Test1']").click()
#second example
select_category = driver.find_element_by_id('id_category') for option in select_category.find_elements_by_tag_name('option'):
if option.text == 'Test1':option.click()
Я не уверен, но я думаю, что Selenuim видеть только первый вариант, этот с (выбрано = «выбрано»).
Это я ошибка сбщ я получил:
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/[email protected]/components/driver_component.js:8905)
at FirefoxDriver.prototype.findElement (file:///c:/users/konrad/appdata/local/temp/tmpfxvjan/extensions/[email protected]/components/driver_component.js:8914)
at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/konrad/appdata/local/temp/tmpfxvjan/extensions/[email protected]/components/command_processor.js:10884)
at DelayedCommand.prototype.executeInternal_ (file:///c:/users/konrad/appdata/local/temp/tmpfxvjan/extensions/[email protected]/components/command_processor.js:10889)
at DelayedCommand.prototype.execute/< (file:///c:/users/konrad/appdata/local/temp/tmpfxvjan/extensions/[email protected]/components/command_processor.js:10831)
Я получил эту ошибку: Traceback (последний последний звонок): Файл «F: \ projekty \ careerguide \ careerguide \ careerguide \ ft \ tests.py ", строка 68, в test_create_blog_entry_admin select.select_by_visible_text (" Test1 ") Файл" F: \ Python27 \ lib \ site-packages \ selenium-2.41.0-py2.7.egg \ selenium \ webdriver \ support \ select.py ", строка 136, в select_by_visible_text raise NoSuchElementException (" Не удалось найти элемент с видимым текстом:% s "% text) NoSuchElementException: Сообщение: 'Не удалось найти элемент с видимым текстом: Test1' –
И вы «Уверен, что у вас есть опция с текстом« Test1 », именно это в элементе' Select', с которым вы имеете дело? –