使用碎片(和硒)中的隐藏选择元素

德米特里M

我有一个碎片的问题。我尝试执行以下代码:

# -*- 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/[email protected]/components/command_processor.js:8791:5)

我尝试使用硒:

# -*- 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/[email protected]/components/command_processor.js:8791:5)

我究竟做错了什么?谢谢。

德米特里M

我找到了解决方案。该站点使用伪选择。对于Splinter之后:

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

需要写

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

辛苦了

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章