使用Python Selenium键入输入字段时出错

时间:2017-02-02 22:16:36

标签: python selenium

我的目标是能够根据我在Python中输入的输入打开和导航网页。

目前我在将字符串输入插入" Street#"时遇到问题。字段,并继续得到以下错误:

AttributeError: 'list' object has no attribute 'send_key'

Text Fields

这是我的代码:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary(r"C:...\firefox.exe")

# Open a Web Browser
browser = webdriver.Firefox(firefox_binary = binary)

# Open the 1st Page
browser.get("http://sftreasurer.org/property-tax-payments")
elem_1stClick = browser.find_element_by_css_selector(".ttx_button > div:nth-child(1)")
elem_1stClick.click() # Click on it

# On the 2nd Page
elem_streetNumber = browser.find_elements_by_css_selector("#ContentPlaceHolder1_tbStreetNumber")
elem_streetNumber.send_key("1230")
elem_2ndClick = browser.find_element_by_css_selector("#ContentPlaceHolder1_btnSearch")
elem_2ndClick()

任何人都可以帮我解决这个问题吗?非常感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

你应该替换这一行

elem_streetNumber = browser.find_elements_by_css_selector("#ContentPlaceHolder1_tbStreetNumber")

用这个

elem_streetNumber = browser.find_element_by_css_selector("#ContentPlaceHolder1_tbStreetNumber")

这是因为find_elements_by_css_selector()返回了网络元素列表,而find_element_by_css_selector()只返回一个网络元素