碎片:可见下拉菜单可点击但不可选择
splinter: visible dropdown is clickable but not selectable
我正在尝试 select 通过 splinter 从模态框的下拉列表中获取一些内容。我很容易找到这个下拉菜单,例如:
(Pdb) dropdown = next(i for i in my_browser.find_by_xpath('//select[@name="existing.widgets.user:list"]') if i.visible)
(我正在处理的页面实际上有多个相同的模式,所以我必须获得当前可见的模式。唉..)
下拉可以点击:
(Pdb) dropdown.visible
True
(Pdb) dropdown.click() //succeeds and displays menu
(Pdb)
...但是尝试 select 失败,即使它应该是可见的!
(Pdb) dropdown.select('my_val')
*** ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
Stacktrace:
at fxdriver.preconditions.visible (file:///tmp/tmp6tSmOc/extensions/fxdriver@googlecode.com/components/command-processor.js:9587)
at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmp6tSmOc/extensions/fxdriver@googlecode.com/components/command-processor.js:12257)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmp6tSmOc/extensions/fxdriver@googlecode.com/components/command-processor.js:12274)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmp6tSmOc/extensions/fxdriver@googlecode.com/components/command-processor.js:12279)
at DelayedCommand.prototype.execute/< (file:///tmp/tmp6tSmOc/extensions/fxdriver@googlecode.com/components/command-processor.js:12221)
(Pdb) dropdown.visible
True // what???
(Pdb)
我很确定 select 的论点是正确的,所以我对这里发生的事情一头雾水。
如果一切都失败了,我可以用 xpath 做些什么吗?或者我需要用另一种方式尝试 finding/interacting 元素吗?
HTML情况的部分截图:http://pasteboard.co/1I30ljRl.png
事实证明,多重模态让我着迷。
鉴于我的名称为 'existing.widgets.user:list'
的下拉菜单和所需的 my_val
,失败的 select
调用在其源头具有:
find_by_xpath('//select[@name="%s"]/option[@value="%s"]' % (dropdown['name'], my_val).click()
现在,事实证明这个 find_by_xpath
实际上 returns multiple/duplicate 选项,可能来自多重模态!
(Pdb) blah=my_browser.find_by_xpath('//select[@name="%s"]/option[@value="%s"]' % (dropdown['name'], my_val)
(Pdb) blah
[<splinter.driver.webdriver.WebDriverElement object at 0x7f7205ff3750>, <splinter.driver.webdriver.WebDriverElement object at 0x7f7205ff39d0>, <splinter.driver.webdriver.WebDriverElement object at 0x7f7205ff38d0>, <splinter.driver.webdriver.WebDriverElement object at 0x7f7205ff3610>]
(Pdb) [bl.value for bl in blah]
[u'my_val', u'my_val', u'my_val', u'my_val']
(Pdb) [bl.visible for bl in blah]
[False, True, False, False]
我想我可以通过正确的模式(例如,使用特定形式 class)而不是通过整个页面访问选项来解决这个问题;即,以
之类的内容开头
form = my_browser.find_by_xpath('//form[@id="{0}"]'.format(my_current_modal))
...然后尝试
dropdown = form.find_by_xpath(...)
dropdown.select(...)
etc.
但是导致了同样的问题;仍然找到多个元素,但仍然失败!所以,我求助于可见性检查,这确实有效:
opts = form.find_by_xpath('//select[@name="%s"]/option[@value="%s"]' % (dropdown['name'], my_val)
next(opt for opt in opts if opt.visible).click()
也许我在这里还缺少一些东西......或者甚至是 Splinter 的一些错误,但至少它有效!
我正在尝试 select 通过 splinter 从模态框的下拉列表中获取一些内容。我很容易找到这个下拉菜单,例如:
(Pdb) dropdown = next(i for i in my_browser.find_by_xpath('//select[@name="existing.widgets.user:list"]') if i.visible)
(我正在处理的页面实际上有多个相同的模式,所以我必须获得当前可见的模式。唉..)
下拉可以点击:
(Pdb) dropdown.visible
True
(Pdb) dropdown.click() //succeeds and displays menu
(Pdb)
...但是尝试 select 失败,即使它应该是可见的!
(Pdb) dropdown.select('my_val')
*** ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
Stacktrace:
at fxdriver.preconditions.visible (file:///tmp/tmp6tSmOc/extensions/fxdriver@googlecode.com/components/command-processor.js:9587)
at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmp6tSmOc/extensions/fxdriver@googlecode.com/components/command-processor.js:12257)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmp6tSmOc/extensions/fxdriver@googlecode.com/components/command-processor.js:12274)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmp6tSmOc/extensions/fxdriver@googlecode.com/components/command-processor.js:12279)
at DelayedCommand.prototype.execute/< (file:///tmp/tmp6tSmOc/extensions/fxdriver@googlecode.com/components/command-processor.js:12221)
(Pdb) dropdown.visible
True // what???
(Pdb)
我很确定 select 的论点是正确的,所以我对这里发生的事情一头雾水。
如果一切都失败了,我可以用 xpath 做些什么吗?或者我需要用另一种方式尝试 finding/interacting 元素吗?
HTML情况的部分截图:http://pasteboard.co/1I30ljRl.png
事实证明,多重模态让我着迷。
鉴于我的名称为 'existing.widgets.user:list'
的下拉菜单和所需的 my_val
,失败的 select
调用在其源头具有:
find_by_xpath('//select[@name="%s"]/option[@value="%s"]' % (dropdown['name'], my_val).click()
现在,事实证明这个 find_by_xpath
实际上 returns multiple/duplicate 选项,可能来自多重模态!
(Pdb) blah=my_browser.find_by_xpath('//select[@name="%s"]/option[@value="%s"]' % (dropdown['name'], my_val)
(Pdb) blah
[<splinter.driver.webdriver.WebDriverElement object at 0x7f7205ff3750>, <splinter.driver.webdriver.WebDriverElement object at 0x7f7205ff39d0>, <splinter.driver.webdriver.WebDriverElement object at 0x7f7205ff38d0>, <splinter.driver.webdriver.WebDriverElement object at 0x7f7205ff3610>]
(Pdb) [bl.value for bl in blah]
[u'my_val', u'my_val', u'my_val', u'my_val']
(Pdb) [bl.visible for bl in blah]
[False, True, False, False]
我想我可以通过正确的模式(例如,使用特定形式 class)而不是通过整个页面访问选项来解决这个问题;即,以
之类的内容开头form = my_browser.find_by_xpath('//form[@id="{0}"]'.format(my_current_modal))
...然后尝试
dropdown = form.find_by_xpath(...)
dropdown.select(...)
etc.
但是导致了同样的问题;仍然找到多个元素,但仍然失败!所以,我求助于可见性检查,这确实有效:
opts = form.find_by_xpath('//select[@name="%s"]/option[@value="%s"]' % (dropdown['name'], my_val)
next(opt for opt in opts if opt.visible).click()
也许我在这里还缺少一些东西......或者甚至是 Splinter 的一些错误,但至少它有效!