运行python selenium脚本时找不到文本字段

时间:2013-06-27 12:04:37

标签: python selenium webdriver

我在网页上有一个文本字段,我想要提供数据,但问题是我的python-selenium脚本在运行并到达该页面时无法找到它。奇怪的是当我尝试手动找到这个文本字段时,我能够毫无问题地这样做。我正在使用CSSSelector找到这个字段。

堆栈追踪:

Traceback (most recent call last):
  File "C:/SWInstallation/TestCases/TestCases\Program.py", line 23, in test_UC_QS_FR_01_1_QuikShip_Support
bhp.enterAccDetails("0004341080", "00200")
File "C:\SWInstallation\HC-Branch\src\HomePage.py", line 24, in enterAccDetails
accInputField = self.driver.find_element_by_css_selector("#fields input[name='ACCOUNT_NUMBER']")
File "C:\Python27\lib\selenium\webdriver\remote\webdriver.py", line 366, in find_element_by_css_selector
return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
File "C:\Python27\lib\selenium\webdriver\remote\webdriver.py", line 680, in find_element
{'using': by, 'value': value})['value']
File "C:\Python27\lib\selenium\webdriver\remote\webdriver.py", line 165, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\selenium\webdriver\remote\errorhandler.py", line 158, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: u"Unable to find element with css selector == #fields input[name='ACCOUNT_NUMBER']" 

1 个答案:

答案 0 :(得分:0)

你有没有试过这样的事情:

e = self.driver.find_element_by_id("fields")
inputs = e.find_elements_by_css_selector("input[name='ACCOUNT_NUMBER']")