Work with hidden select elemens in splinter (and selenium)

試著忘記壹切 提交于 2019-12-11 18:50:54

问题


I have a problem with splinter. I try to execute this code:

# -*- 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")

But get this error:

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)

I try to use selenium:

# -*- 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')

But get the same error:

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)

What am I doing wrong? Thanks.


回答1:


I find the solution. This site use pseudo select. For Splinter after:

browser.find_by_name("hint_question_id").click()

needs write

browser.find_by_css("li[role=\"presentation\"]")[1].click()
browser.find_by_id("hint_answer").fill(firstname)

Work good.



来源:https://stackoverflow.com/questions/25322525/work-with-hidden-select-elemens-in-splinter-and-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!