我正在尝试编写一个 Selenium 驱动程序来测试使用下拉(组合)检查列表的网页。以下代码显示了该问题。
#!/usr/bin/python
from selenium import webdriver
from selenium.webdriver.support.ui import Select
driver = webdriver.Firefox()
driver.get("http://dropdown-check-list.googlecode.com/svn/trunk/doc/ddcl-tests.html")
selector = driver.find_element_by_id("s1")
allOptions = selector.find_elements_by_tag_name("option")
for option in allOptions:
print "Value is", option.get_attribute("value")
option.click()
当我运行它时,我得到以下输出:
Value is Low
Traceback (most recent call last):
File "./ddcl-test.py", line 24, in <module>
option.click()
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py", line 51, in click
self._execute(Command.CLICK_ELEMENT)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py", line 225, in _execute
return self._parent.execute(command, params)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 160, in execute
self.error_handler.check_response(response)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 149, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: u'Element is not currently visible and so may not be interacted with' ; Stacktrace: Method fxdriver.preconditions.visible threw an error in file:///var/folders/d4/qbgb29wx7z7fpr15t___x24h0000gn/T/tmpBzUUcu/extensions/fxdriver@googlecode.com/components/command_processor.js
它无法单击元素,因为它没有显示。
我该如何解决这个问题?或者这是 Selenium 中无法测试的案例?