Перейти к содержимому

gumbert

Регистрация: 15 авг 2014
Offline Активность: 17 авг 2014 10:06
-----

Мои темы

Работа с элементами select в splinter или selenium (python 2.7)

15 августа 2014 - 07:21

Привет. Осваиваю библиотеку splinter и selenium для python. Возникли затруднения. Итак, я выполняю следующий код в splinter:

    # -*- coding: utf-8 -*-
    from splinter import Browser

    browser = Browser()
    browser.visit('https://passport.yandex.com/registration/mail')
    browser.find_by_name("hint_question_id").click()
    browser.select("hint_question_id","12")

Но вижу следующую ошибку:

    selenium.common.exceptions.ElementNotVisibleException: Message: u'Element is not currently visible and so may not be interacted with' ; Stacktrace:
    at fxdriver.preconditions.visible (file:///c:/users/dm/appdata/local/temp/tmppiwmlb/extensions/fxdriver@googlecode.com/components/command_processor.js:8791:5)

Как так? Ведь клик по выпадающему списку происходит и все элементы становятся видны.

Попробовал выполнить действие в seleium:

    # -*- coding: utf-8 -*-
    from selenium import webdriver
    from selenium.webdriver.support.ui import Select

    driver = webdriver.Firefox()
    driver.get("https://passport.yandex.com/registration/mail")

    driver.find_element_by_name("hint_question_id").click()

    # navigate to the page
    select = Select(driver.find_element_by_tag_name("select"))
    print select.options
    print [o.text for o in select.options] # these are string-s
    select.select_by_index('2')

Но вижу ту же самую ошибку.

    selenium.common.exceptions.ElementNotVisibleException: Message: u'Element is not currently visible and so may not be interacted with' ; Stacktrace:
    at fxdriver.preconditions.visible (file:///c:/users/dm/appdata/local/temp/tmpzjqnnp/extensions/fxdriver@googlecode.com/components/command_processor.js:8791:5)

Что я делаю не так? Как можно выбирать нужный элемент в подобном случае? Благодарю за разъяснения.